[英]Google spreadsheet script time limit of execution
I've written gs script to clear data from all cells in sheets. 我写了gs脚本来清除工作表中所有单元格的数据。 Spreadsheet has a lot of sheets (about 200) and I get error of time limit execution.
电子表格有很多工作表(约200),我得到时间限制执行错误。 Maybe somebody have ideas how to resolve this issue.
也许有人有想法如何解决这个问题。 Here example of my code.
这是我的代码示例。
function cleanAllOld() {
var sheetsName = new Array();
var destination = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/link");
var sheets = destination.getSheets();
for (var k = 0; k < sheets.length; k++) {
sheetsName.push([sheets[k].getName()]);
for (var p = 0; p < sheetsName.length; p++) {
var sheet = destination.getSheetByName(sheetsName[p]);
if (sheet === null) {} else {
sheet.getDataRange().clearContent();
}
}
}
}
I don't get all the part of your code, but I think he's too complicated for nothing. 我没有得到你的代码的所有部分,但我认为他太复杂,没有任何东西。 Here's is a sample which work:
这是一个工作的样本:
function AllDelete() {
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/link");
var sheets = ss.getSheets();
var i = 0;
for(i in sheets){
sheets[i].clearContents();
}
}
Edit: Max is fast and is right, the getDataRange() method is using a lot of ressources 编辑:Max很快且正确,getDataRange()方法使用了大量的资源
I think the problem is geting data range. 我认为问题在于确定数据范围。
Try replace this 尝试更换它
sheet.getDataRange().clearContent();
by this: 这样:
sheet.clearContents();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.