另一张纸更改时更新整张纸(脚本)

问题描述 投票:0回答:1

我有一个Google电子表格,其中包含主页上的论文名称(称为“ABSTRACTS”)。其中一列表示是否已在实验室中讨论过该论文(“si”,“no”)。当列中显示“si”(是)时,脚本将论文名称和信息复制到另一个名为“Seminarios”(研讨会)的表格中,如果列中显示“否”,则将信息复制到另一个名为“DISCUTIR”的表格中(以进行讨论) )。该脚本工作正常(它将信息复制到适当的表)但它有一点问题。当我们讨论论文并将其状态从“否”更改为“是”时,它会将其添加到SEMINARIO表中,但不会将其从“DISCUTIR”表中删除。有没有办法让脚本刷新整个工作表? (如果我删除“DISCUTIR”表的全部内容,它只会添加我想要的内容,但我想找到一种自动执行的方法)。

在这里,我附上我正在使用的代码。我确定它真的不整洁和低效,因为我不知道我在做什么所以我为此道歉。我在MATLAB中有一些编程经验,但从未使用过JavaScript,只是设法通过复制和粘贴代码来使其工作。

function onEdit(e) {
  var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ABSTRACTS");
  var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SEMINARIOS");
  var sheetTo2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DESCARTADOS");
  var sheetTo3 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DISCUTIR");
  var sheetTo4 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CHEQUEAR");

  var data = sheetFrom.getDataRange().getValues();
  var target = new Array(); // this is a new array to collect data
  for (n = 0; n < data.length; ++n) { // iterate in the array, row by row
    if (data[n][8] == "si") { // if condition is true copy the whole row to target
      target.push(data[n]); // copy the whole row
    } //if
  } //for

  //Paste to another sheet from first cell onwards
  sheetTo.getRange(2, 1, target.length, target[0].length).setValues(target);

  var data = sheetFrom.getDataRange().getValues();
  var target = new Array(); // this is a new array to collect data
  for (n = 0; n < data.length; ++n) { // iterate in the array, row by row
    if (data[n][8] == "descartado") { // if condition is true copy the whole row to target
      target.push(data[n]); // copy the whole row
    } //if
  } //for

  //Paste to another sheet from first cell onwards
  sheetTo2.getRange(2, 1, target.length, target[0].length).setValues(target);

  var data = sheetFrom.getDataRange().getValues();
  var target = new Array(); // this is a new array to collect data
  for (n = 0; n < data.length; ++n) { // iterate in the array, row by row
    if (data[n][8] == "no") { // if condition is true copy the whole row to target
      target.push(data[n]); // copy the whole row
    } //if
  } //for

  //Paste to another sheet from first cell onwards
  sheetTo3.getRange(2, 1, target.length, target[0].length).setValues(target);

  var data = sheetFrom.getDataRange().getValues();
  var target = new Array(); // this is a new array to collect data
  for (n = 0; n < data.length; ++n) { // iterate in the array, row by row
    if (data[n][8] == "chequear") { // if condition is true copy the whole row to target
      target.push(data[n]); // copy the whole row
    } //if
  } //for

  //Paste to another sheet from first cell onwards
  sheetTo4.getRange(2, 1, target.length, target[0].length).setValues(target);

}
javascript google-apps-script google-sheets conditional refresh
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.