Hon*_*gli 3 google-sheets google-apps-script
我正在使用Google电子表格进行税务管理.我在一年内完成的所有财务交易都在电子表格中.因为我国的税收规则非常复杂,所以我开发了许多JavaScript函数来帮助我计算.我的电子表格中有很多行,大约1000行.每行都有多个对这些JavaScript函数的引用.
这个系统之前运行得非常好,但今天我发现Google在Google Spreadsheet中安装了某种运行时限制系统,导致我的许多列中止以下错误:
Service invoked too many times in a short time: exec maxSimultaneous.
Try Utilities.sleep(1000) between calls.
Run Code Online (Sandbox Code Playgroud)
经过一些调查后,似乎这个时间限制可以防止脚本运行时间过长.我的情况不同:我的脚本都是简短的O(1)算法,除了计算一些数字之外什么都不做.典型的脚本如下所示:
// Calculates the total amount excluding Value Added Tax, given
// an amount including Value Added Tax, and other sorts of information.
function ex_btw(inc_btw, commentaar, soort, btw_verlegd, btw_pct) {
Utilities.sleep(1000);
var soort = soort.toLowerCase();
if (soort == 'eten en drinken'
|| commentaar.match(/treinkaartje/i)
|| commentaar.match(/treinticket/i)
|| commentaar.match(/taxi/i)
|| commentaar.match(/ boek /i))
{
return inc_btw / 1.06;
} else if (soort == 'priveonttrekking'
|| soort == 'boete'
|| soort == 'belasting'
|| commentaar.match(/postzegel/i)
|| btw_verlegd == 'Ja')
{
return inc_btw;
} else {
return inc_btw / (1 + btw_pct);
}
}
Run Code Online (Sandbox Code Playgroud)
然后从单元格中调用脚本:
=IF(B6<>""; ex_btw(B6;D6;E6;J6;S6); "")
Run Code Online (Sandbox Code Playgroud)
也许我的问题是我有太多的脚本调用.每一行调用大约6个这样的脚本,因此对于1000行,我每个电子表格调用6000次.
我该如何解决这个问题?有没有办法增加执行限制,还是有办法让脚本运行得更慢,以至于它们没有达到执行限制?正如您在示例代码中看到的,我已经尝试过插入Utilities.sleep(1000),但这似乎无法解决问题.我不关心脚本是否运行缓慢,我只关心它们完成没有错误.
我可以支付限额增加吗?我需要在几天内交税.
我考虑过的其他替代方案,但这是不可行的.
有一个庞大的JavaScript函数,它遍历行并填充单元格.不可行,因为:
我通过让每个函数在一段随机时间内休眠来解决它,如下所示:
Utilities.sleep(Math.random() * 5000);
Run Code Online (Sandbox Code Playgroud)
睡眠时间是随机的,而不是恒定的,这一点很重要.显然,谷歌限制了可能同时使用CPU的最大功能数量.
| 归档时间: |
|
| 查看次数: |
4011 次 |
| 最近记录: |