Lembar google jika kotak centang dicentang sembunyikan baris

Saya mencoba menemukan kode kerja yang secara otomatis akan menyembunyikan baris jika kotak centang di kolom F baris itu dicentang

Saya telah mencoba setiap skrip yang saya temukan dan sepertinya tidak ada yang berhasil. Sayangnya saya tidak paham kode dan saya tidak dapat menemukan masalahnya

Inilah yang saya miliki saat ini

function onOpen() {
  var s = SpreadsheetApp.getActive().getSheetByName("Checklists");
  s.showRows(1, s.getMaxRows());

  s.getRange('F2:F200')
    .getValues()
    .forEach( function (r, i) {
    if (r[0] == "TRUE") 
      s.hideRows(i + 1);
    });
}

Lembar yang saya kerjakan adalah "Daftar Periksa" dan kolom yang berisi kotak centang adalah F. Nilai kotak centang adalah BENAR atau SALAH. Jika nilainya BENAR, saya ingin baris itu disembunyikan

Dapatkah seseorang tolong bantu

Solusi terbaik

Tes cepat yang dapat saya jalankan adalah menyiapkan kolom kotak centang di kolom F, lalu membuat fungsi yang menangkap setiap acara edit di lembar. Ini akan segera menangkap ketika pengguna mencentang kotak dan kemudian akan menyembunyikan baris itu

Trik dengan menggunakan acara

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
_0 adalah dengan menentukan sel mana yang sebenarnya diubah. Dalam kasus Anda, Anda hanya ingin sepenuhnya mengikuti logika Anda jika perubahan terjadi pada kotak centang di kolom F. Dalam kode saya, saya telah menggunakan fungsi untuk memastikan perubahan berada dalam rentang yang diinginkan. Fungsinya terlihat seperti ini

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
_

Jadi semua fungsi

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
0 Anda harus dilakukan adalah melakukan panggilan cepat saat acara edit diaktifkan untuk melihat apakah perubahan berada dalam rentang yang Anda cari. Dalam hal ini, saya menyiapkan variabel dengan jangkauan saya untuk diperiksa

var thisSheet = SpreadsheetApp.getActiveSheet();
var checkRange = thisSheet.getRange("F2:F200");  
if (isInRange(checkRange, eventObj.range)) {
_

Setelah itu, tinggal memilih nomor baris dan menyembunyikan atau menampilkannya. Berikut contoh lengkap solusinya

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}

function onEdit(eventObj) {
  //--- you could set up a dynamic named range for this area to make it easier
  var thisSheet = SpreadsheetApp.getActiveSheet();
  var checkRange = thisSheet.getRange("F2:F200");  
  if (isInRange(checkRange, eventObj.range)) {
    //--- so one of the checkboxes has changed its value, so hide or show
    //    that row
    var checkbox = eventObj.range;
    var rowIndex = checkbox.getRow();
    Logger.log('detected change in checkbox at ' + checkbox.getA1Notation() + ', value is now ' + checkbox.getValue());
    if (checkbox.getValue() == true) {
      Logger.log('hiding the row');
      thisSheet.hideRows(rowIndex, 1);
    } else {
      Logger.log('showing the row');
      thisSheet.showRows(rowIndex, 1);
    }
  }
}

Solusi Terkait

Javascript – Mengatur “dicentang” untuk kotak centang dengan jQuery

jQuery modern

Gunakan

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
_2

$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);

API DOM

Jika Anda bekerja hanya dengan satu elemen, Anda selalu dapat mengakses

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
3 yang mendasarinya dan memodifikasi propertinya

$('.myCheckbox')[0].checked = true;
$('.myCheckbox')[0].checked = false;
_

Manfaat menggunakan metode

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
_2 dan
function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
6 daripada metode ini adalah metode tersebut akan beroperasi pada semua elemen yang cocok

jQuery 1. 5. x dan di bawahnya

Metode

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
2 tidak tersedia, jadi Anda perlu menggunakan
function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
6

$('.myCheckbox').attr('checked', true);
$('.myCheckbox').attr('checked', false);

Perhatikan bahwa ini adalah dan lebih disukai untuk menggunakan

function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
_9 karena yang terakhir akan, jika kotak awalnya dicentang, mengubah perilaku panggilan ke
var thisSheet = SpreadsheetApp.getActiveSheet();
var checkRange = thisSheet.getRange("F2:F200");  
if (isInRange(checkRange, eventObj.range)) {
0 pada formulir apa pun yang berisi itu – perubahan perilaku yang halus tapi mungkin tidak diinginkan

Untuk konteks lebih lanjut, beberapa diskusi tidak lengkap tentang perubahan penanganan

var thisSheet = SpreadsheetApp.getActiveSheet();
var checkRange = thisSheet.getRange("F2:F200");  
if (isInRange(checkRange, eventObj.range)) {
1 atribut/properti dalam transisi dari 1. 5. x ke 1. 6 dapat ditemukan di versi 1. 6 catatan rilis dan Atribut vs. Bagian properti dari dokumentasi
function isInRange(checkRange, targetCell) {
  //--- check the target cell's row and column against the given
  //    checkrange area and return True if the target cell is
  //    inside that range
  var targetRow = targetCell.getRow();
  if (targetRow < checkRange.getRow() || targetRow > checkRange.getLastRow()) return false;

  var targetColumn = targetCell.getColumn();
  if (targetColumn < checkRange.getColumn() || targetColumn > checkRange.getLastColumn()) return false;

  //--- the target cell is in the range!
  return true;
}
2

Bagaimana cara menyembunyikan baris jika kotak centang di Google Sheets dicentang?

Ada beberapa cara untuk menyembunyikan baris di Google Spreadsheet. Salah satu caranya adalah dengan menggunakan fungsi sembunyikan . Untuk menyembunyikan baris, pilih baris yang ingin Anda sembunyikan, lalu klik tombol "sembunyikan" di bilah alat. Cara lain untuk menyembunyikan baris adalah dengan menggunakan fungsi filter.

Bisakah Anda menyembunyikan baris secara kondisional di Google Sheets?

Ya, Anda bisa . Filter Google Sheets memungkinkan Anda menentukan kondisi menggunakan "lebih besar dari" atau "kurang dari" dan seterusnya, ini dapat menyembunyikan baris di Google Sheets secara kondisional.

Bagaimana cara menyorot baris jika kotak centang di Google Sheets dicentang?

Contoh .
Langkah 1. Pilih rentang sel kotak centang. Pilih rentang sel kotak centang yang akan disertakan dalam format bersyarat. .
Langkah 2. Pilih Format > Pemformatan bersyarat. .
Langkah 3. Ubah aturan format. .
Langkah 4. Pilih Selesai untuk melihat hasilnya

Bagaimana Anda secara otomatis menyembunyikan baris berdasarkan lembar nilai sel?

Untuk menyembunyikan baris berdasarkan nilai sel, cukup klik menu Filter Rows, dan pilih perintah Filter Rows . Saat Anda mengklik perintah tersebut, perhatikan bahwa Google Sheets akan secara otomatis menyembunyikan catatan yang telah ditandai sebagai dibayar di spreadsheet Anda.