我的代码只是简单地将电子表格A中的数据添加到电子表格B.在电子表格A具有21行数据并且电子表格B只有20行的情况下,我的脚本显然是试图写入电子表格中的一行B不存在。所以脚本显然会自动添加50行以为多余的数据腾出空间。为什么Google脚本会自动添加50行?
有没有办法阻止它增加50行,当一行就足够了?
这通常不会打扰我...但电子表格B格式化,它会自动复制下来50行。当电子表格B发布到我们的网站时,这种格式不正确。
这是我的代码。当rowCounterDTL
变量超过存在于电子表格乙行数,50行被自动添加到电子表格B.
//Cycle through each line item in the task log
for (var i = 0; i < dataTL.length; ++i) {
//If the package type is Other
if(dataTL[i][2] == "Other Item" && dataTL[i][4] == "Complete") {
continue;
} else if (dataTL[i][2] == "Other Item") {
rowCounterDTL = rowCounterDTL + 1
var daysOld = Math.round((todaysDate - dataTL[i][0])/1000/60/60/24);
sheetDTL.getRange(rowCounterDTL,1).setValue(dataTL[i][1]); //Add the client ID to column 1 of the DTL
sheetDTL.getRange(rowCounterDTL,2).setValue(dataTL[i][2]); //Add the package type to column 2 of the DTL
sheetDTL.getRange(rowCounterDTL,3).setValue(dataTL[i][3]); //Add the package notes to column 3 of the DTL
sheetDTL.getRange(rowCounterDTL,4).setValue(dataTL[i][4]); //Add the package priority to column 4 of the DTL
sheetDTL.getRange(rowCounterDTL,5).setValue(daysOld); //Add the age to column 5 of the DTL
if (daysOld>20){
sheetDTL.getRange(rowCounterDTL,6).setValue("On Hold?");
} else if(daysOld>7) {
sheetDTL.getRange(rowCounterDTL,6).setValue("Max!");
} else if (daysOld>4){
sheetDTL.getRange(rowCounterDTL,6).setValue("High");
} else if (daysOld>2){
sheetDTL.getRange(rowCounterDTL,6).setValue("Moderate");
} else if (daysOld<3){
sheetDTL.getRange(rowCounterDTL,6).setValue("Low");
}
sheetDTL.getRange(rowCounterDTL,1,1,6).setBackgroundRGB(255, 121, 255)
}
}
放一些代码。也许我们可以帮助你。 – sircapsalot
补充,谢谢。 – user1569724
你的代码中是否有这行代码? 'for(var i = 0; i
sircapsalot