スプレッドシートAからスプレッドシートBにデータを追加するだけのコードがあります。スプレッドシートAに21行のデータがあり、スプレッドシートBに20行しかない場合、スクリプトは明らかにスプレッドシートBの行に書き込もうとしています。存在しません。したがって、スクリプトは明らかに自動的に50行を追加して、余分なデータ用のスペースを確保します。
1行で十分な場合に、50行が追加されないようにする方法はありますか?
これは通常は気になりません...しかし、スプレッドシートBにはフォーマットが含まれており、自動的に50行下にコピーされます。スプレッドシートBが当社のWebサイトに公開されている場合、このフォーマットは正しく表示されません。
これが私のコードです。変数がスプレッドシート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)
}
}