0
我有一個谷歌電子表格,可以讓我跟蹤成本和項目金額。我寫了一個腳本來更新這些值;然而,今天它只是掛在getRange或getDataRange上,即使在調試時也是如此。昨天工作正常。Google表格腳本掛在getDataRange或getRange
<code>function onOpen() {
var menuEntries = [{name: "Update P0", functionName: "UpdateP0"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu("PI Utils", menuEntries);
}
function showMsg(data, title, timeout) {
if (typeof title == 'undefined') title = "";
if (typeof timeout == 'undefined') timeout = 5;
SpreadsheetApp.getActiveSpreadsheet().toast(data, title, timeout);
}
function UpdateP0() {
showMsg("Updating...", "", -1);
var piSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('PI (Set1)');
piSheet.activate();
//SpreadsheetApp.flush();
var numPlanets = 5;
try {
var dRange = piSheet.getRange('A1:F55'); // will not execute pass this line
} catch (e) {
throw (e);
return;
}
for (var p = 1, prGroup = 1; p <= numPlanets; p++, prGroup += 11) {
var cell1, cell2, v1, v2;
// update extraction amounts
for (var r = 0; r < 3; r++) {
cell1 = dRange.getCell(prGroup + 2 + r, 3);
cell2 = dRange.getCell(prGroup + 2 + r, 4);
v1 = cell1.getValue().toString();
v2 = cell2.getValue().toString();
v1 = (v1.length == 0) ? parseFloat(0.0) : parseFloat(v1);
v2 = (v2.length == 0) ? parseFloat(0.0) : parseFloat(v2);
v2 += v1;
cell1.setValue(0);
cell2.setValue(v2);
}
// update production costs
for (var c = 2; c <= 5; c++) {
cell1 = dRange.getCell(prGroup + 9, c);
cell2 = dRange.getCell(prGroup + 8, c);
v1 = cell1.getValue().toString();
v2 = cell2.getValue().toString();
v1 = (v1.length == 0) ? parseFloat(0.0) : parseFloat(v1);
v2 = (v2.length == 0) ? parseFloat(0.0) : parseFloat(v2);
v2 += v1;
cell1.setValue(0);
cell2.setValue(v2);
}
}
SpreadsheetApp.flush();
showMsg("Completed.", "", 5);
}</code>
調試器似乎總是掛在一個catch塊中。嘗試使用'運行'來檢查執行腳本('查看' - '執行腳本'),看看代碼是否失敗。 –
我添加try-catch塊之前存在問題。我刪除了它並刪除了showMsg行,但它仍然在我從電子表格運行時掛起,並且在調試時掛起在getRange上。 –