Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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
Optimization 如何在Google应用程序脚本中加速行删除功能_Optimization_Google Apps Script_Google Sheets - Fatal编程技术网

Optimization 如何在Google应用程序脚本中加速行删除功能

Optimization 如何在Google应用程序脚本中加速行删除功能,optimization,google-apps-script,google-sheets,Optimization,Google Apps Script,Google Sheets,我正在尝试运行几百行数据,并删除C和D中均为0的行。删除符合该情况的行似乎可行,但确实需要花费时间。我是一个脚本新手(我不是程序员,只是想学习),我不知道如何使它更快。主脚本来自其他人,我添加了逻辑来做两列而不是一列。有什么想法吗 function deleteZeroes() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var s = ss.getSheetByName('Email_Help_Total_Input'); v

我正在尝试运行几百行数据,并删除C和D中均为0的行。删除符合该情况的行似乎可行,但确实需要花费时间。我是一个脚本新手(我不是程序员,只是想学习),我不知道如何使它更快。主脚本来自其他人,我添加了逻辑来做两列而不是一列。有什么想法吗

function deleteZeroes() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName('Email_Help_Total_Input');
  var range1 = s.getRange('C:C');
  var cValues = range1.getValues();
  var range2 = s.getRange('D:D');
  var dValues = range2.getValues();  

  for(var i=cValues.length-1;i>=0;i--)
    if(cValues[0,i]==0 && dValues[0,i]== 0) 
      s.deleteRow(i+1);

}

它起作用了,但很慢。只是想快点。谢谢

数组而不是读写

data = s.getDataRange().getValues();
result = [];

for (i=0;i<data.length;i++) {
   if (data[i][2]==0) continue; //checks C, if it finds it continues the loop
   if (data[i][3]==0) continue; //checks D, if it finds it continues the loop
   result.push(data[i]);//only those that fell through the 0 checks will be here
}
s.getDataRange().clear();
s.getRange(1,1,result.length,result[0].length).setValues(result);
data=s.getDataRange().getValues();
结果=[];

对于(i=0;i数组,而不是读写

data = s.getDataRange().getValues();
result = [];

for (i=0;i<data.length;i++) {
   if (data[i][2]==0) continue; //checks C, if it finds it continues the loop
   if (data[i][3]==0) continue; //checks D, if it finds it continues the loop
   result.push(data[i]);//only those that fell through the 0 checks will be here
}
s.getDataRange().clear();
s.getRange(1,1,result.length,result[0].length).setValues(result);
data=s.getDataRange().getValues();
结果=[];

对于(i=0;问题的代码不完整。它只遗漏了功能块关闭括号吗?参考。问题的代码不完整。它只遗漏了功能块关闭括号吗?参考。注意,写入保留值与删除特定行不同。请考虑公式、筛选器、命名范围、格式设置;etc@J.G.,非常感谢我在理解数组时遇到了困难,但这确实很有帮助。它运行得非常快,但去掉了C列和D列中0的每一个实例。最终的结果是C列和D列中都有0的每一行都被删除,其他所有实例都保持不变。我添加了“and”的逻辑在C和D之间,得到了以下结果,非常有效!因此if语句现在看起来是这样的:
if(data[i][2]==0&&data[i][3]==0)继续,注意,写入保留值与删除特定行不同。请考虑公式、筛选器、命名范围、格式设置;etc@J.G.,非常感谢您的洞察力!我在理解数组时遇到了困难,但这确实很有帮助。它运行速度非常快,但可以消除C列和D列中0的每个实例。最终结果是如果C和D中都有0的每一行都被删除,其他所有实例都保持不变。我在C和D之间添加了“and”的逻辑,得到了以下结果,效果非常好!因此if语句现在看起来是这样的:
if(data[I][2]==0&&data[I][3]==0)continue;