javascript - 谷歌脚本超时
问题描述
多年来,我一直在 Excel 中使用宏,并希望将其翻译成谷歌脚本以在云端硬盘中进行协作。
我正在使用两张表设置(一张名为“BILAN”,这是概述,另一张名为 INPUT 用于输入数据。该脚本在没有太多输入的情况下工作得很好,但我希望达到近一千个输入在文件使用结束时。
基本上,脚本是一个双循环来总结 BILAN 表中的输入。在此先感谢您的帮助 !!
这是我正在使用的代码:
function getTransportDates() {
var ss = SpreadsheetApp.getActive();
var strDatesTransport = '';
const intNbClients = ss.getSheetByName('BILAN').getDataRange().getLastRow();
const intNbInputs = ss.getSheetByName('INPUT').getDataRange().getLastRow();
for (let i = 4; i <= intNbClients; i++) { // loop through the addresses in BILAN
if (ss.getSheetByName('BILAN').getRange(i, 9).getValue() >0) {
for (let j = 4; j <= intNbInputs; j++) { // loop through the adresses in INPUT
if (ss.getSheetByName('INPUT').getRange(j, 2).getValue() == ss.getSheetByName('BILAN').getRange(i, 1).getValue()) {
strDatesTransport = strDatesTransport + ' // ' + ss.getSheetByName('INPUT').getRange(j, 1).getValue(); //.toISOString().split('T')[0];
}
}
}
ss.getSheetByName('BILAN').getRange(i, 10).setValue(strDatesTransport);
strDatesTransport = '';
}
};
解决方案
试试这种方式:
function getTransportDates() {
const ss = SpreadsheetApp.getActive();
var sdt = '';
const csh = ss.getSheetByName('BILAN');
const cvs = csh.getRange(4, 1, csh.getLastRow() - 3, csh.getLastColumn()).getValues();
const ish = ss.getSheetByName('INPUT');
const ivs = ish.getRange(4, 1, ish.getLastRow() - 3, ish.getLastColumn()).getValues();
cvs.forEach((cr,i) => {
if((cr[8] > 0)) {
ivs.forEach((ir,j)=>{
if(ir[1] == cr[0]) {
sdt += ir[0];
}
});
}
ss.getSheetByName('BILAN').getRange(i + 4, 10).setValue(sdt);
sdt = '';
});
}
不知道这是哪里://.toISOString().split('T')[0];
推荐阅读
- solr - 如何通过在 SOLR 7.1.0 中应用 PatternReplaceFilterFactory 来转换/更新和存储传入的 JSON 属性
- xml - 我需要从不将第一行保存为标签的 csv 文件创建一个 xml 文件
- java - 在 TableCell 中更改背景颜色会删除选择颜色,使其难以阅读
- php - 使用 SQL 组合两个数组值以进行插入
- javascript - 我想用不同的动作从 Get 服务中分派 4 个不同的值。想打一个电话
- javascript - 从一组 Angular Material 复选框中获取值?
- ms-access - 我收到运行时错误“94”:无效使用 Null
- angular - Angular 7:@angular/core/core 没有导出成员 'OpaqueToken'
- .htaccess - 如何将多个旧域重定向到新域页面
- python - Tensorflow/XLA:LLVM IR 中的并行操作数