Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets 自动隐藏/取消隐藏行Google电子表格_Google Sheets_Spreadsheet - Fatal编程技术网

Google sheets 自动隐藏/取消隐藏行Google电子表格

Google sheets 自动隐藏/取消隐藏行Google电子表格,google-sheets,spreadsheet,Google Sheets,Spreadsheet,我正在尝试制作一个谷歌电子表格脚本 当单元格的值更改为指定值时,我希望它触发隐藏/取消隐藏行 以下是我目前的脚本: function autoHide() { var ss = SpreadsheetApp.getActive() var sheet = SpreadsheetApp.getActiveSheet() var cell = ss.getActiveCell() var cell1 = ("C12"); if (cell1 == "Others" ) {

我正在尝试制作一个谷歌电子表格脚本

当单元格的值更改为指定值时,我希望它触发隐藏/取消隐藏行

以下是我目前的脚本:

function autoHide() {

  var ss = SpreadsheetApp.getActive()
  var sheet = SpreadsheetApp.getActiveSheet()
  var cell = ss.getActiveCell()
  var cell1 = ("C12");

  if (cell1 == "Others" ) {
    ss.getActiveSheet().showRows(14, 3);
  }

  else if (cell1 == "Additional Discount/s (over and above 25%)" ) {
    ss.getActiveSheet().showRows(17, 4);
  }

  else {
    ss.getActiveSheet().hideRows(14, 7)
  }
}

您的问题在某些方面有点不清楚,因此我假设您希望在编辑C12时跟踪单元格C12的值

function autoHide() {

  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getActiveSheet();
  var cell = ss.getActiveCell();
  var value = cell.getValue();

  var cellRef = cell.getA1Notation();

  if (cellRef !== "C12") return;
  // This isn't the cell we are looking for, stop executing the function.

  if (value === "Others" ) {

    sheet.showRows(14, 3);

  } else if (value === "Additional Discount/s (over and above 25%)" ) {

    sheet.showRows(17, 4);

  } else {
    sheet.hideRows(14, 7);
  }
}

如果要在编辑任何单元格时运行该函数,请使用此代码

如果C12是一个公式且未手动更新,则此选项非常有用

function autoHide() {

  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getActiveSheet();

  var cellRef = "C12";
  var cell = sheet.getRange(cellRef);
  var value = cell.getValue();

  if (value === "Others" ) {

    sheet.showRows(14, 3);

  } else if (value === "Additional Discount/s (over and above 25%)" ) {

    sheet.showRows(17, 4);

  } else {
    sheet.hideRows(14, 7);
  }
}

那么,您当前的脚本有什么问题?每当我更改单元格值时,隐藏/取消隐藏行不起作用。您是否更改单元格
C12
中的值?此外,您在任何时候都不使用方法
cell.getValue()
来检查字符串值。我正在通过一个下拉选项手动更改单元格中的值,我会试试这些代码,如果有用的话就贴在这里