我在运行Google脚本几个月没有任何问题。突然,剧本花了太多时间来执行。我尝试为不同的电子表格运行脚本,并注意到大多数它的工作正常但很少花费太多时间。
以下代码读取两个电子表格“SS 1”和“SS 2”中所有工作表的A1单元格的值。
function Test()
{
Logger.log("SS 1 Start")
var ss = SpreadsheetApp.openById("ID SS 1") //Spreadsheet 1
var sheets = ss.getSheets()
Logger.log(sheets.length)
for(var i = 0; i<sheets.length; i++)
{
Logger.log(sheets[i].getRange("A1").getValue())
}
Logger.log("SS 1 Stop")
Logger.log("SS 2 Start")
var ss = SpreadsheetApp.openById("ID SS 2") //Spreadsheet 2
var sheets = ss.getSheets()
Logger.log(sheets.length)
for(var i = 0; i<sheets.length; i++)
{
Logger.log(sheets[i].getRange("A1").getValue())
}
Logger.log("SS 2 Stop")
}
SS 1有15张,脚本需要差不多一分钟才能读取A1单元格中的值,而SS 2上只需要10秒钟就有21张。 可能是什么问题呢?日志已附加
[17-10-27 19:40:56:116 IST] SS 1 Start
[17-10-27 19:40:56:279 IST] 15.0
[17-10-27 19:40:59:894 IST] PS
[17-10-27 19:41:03:324 IST] WL
[17-10-27 19:41:06:748 IST] PERIOD
[17-10-27 19:41:10:218 IST]
[17-10-27 19:41:13:812 IST]
[17-10-27 19:41:16:987 IST]
[17-10-27 19:41:20:568 IST]
[17-10-27 19:41:24:136 IST]
[17-10-27 19:41:27:803 IST]
[17-10-27 19:41:31:214 IST]
[17-10-27 19:41:34:740 IST]
[17-10-27 19:41:38:538 IST]
[17-10-27 19:41:41:987 IST]
[17-10-27 19:41:45:693 IST]
[17-10-27 19:41:49:313 IST]
[17-10-27 19:41:49:314 IST] SS 1 Stop
[17-10-27 19:41:49:314 IST] SS 2 Start
[17-10-27 19:41:49:421 IST] 21.0
[17-10-27 19:41:50:034 IST]
[17-10-27 19:41:50:422 IST] BCHEM
[17-10-27 19:41:50:831 IST] BIO
[17-10-27 19:41:51:210 IST] BMS
[17-10-27 19:41:51:606 IST] BOT
[17-10-27 19:41:52:017 IST] CHEM
[17-10-27 19:41:52:578 IST] CS
[17-10-27 19:41:52:995 IST] ELEC
[17-10-27 19:41:53:401 IST] FT
[17-10-27 19:41:53:803 IST] INS
[17-10-27 19:41:54:277 IST] MB
[17-10-27 19:41:54:825 IST] PHY
[17-10-27 19:41:55:217 IST] PS
[17-10-27 19:41:55:621 IST] ZOO
[17-10-27 19:41:56:031 IST] PHY-ED
[17-10-27 19:41:56:433 IST] HC
[17-10-27 19:41:56:978 IST] MATHS
[17-10-27 19:41:57:374 IST]
[17-10-27 19:41:57:769 IST]
[17-10-27 19:41:58:588 IST] PERIOD
[17-10-27 19:41:59:031 IST]
[17-10-27 19:41:59:031 IST] SS 2 Stop
Partha S. Pal
答案 0 :(得分:0)
我设置了一些测试电子表格并运行了您的脚本。它完成时间超过7秒,时间分别为41%到51%,这与我预期的15/22张数相同。我建议你创建新的电子表格并再试一次。