0
我剛剛測試了這個腳本10分鐘前,它的工作,現在sudently它拋出一個「服務錯誤:電子表格」。AppsScript setNamedRange導致服務錯誤
調試器不顯示任何東西,我不得不gradualy切換評論,直到我發現,引發錯誤的行:
ss.setNamedRange(namesFlat[j], sheet.getRange(j+2, 26));
粘貼下面的腳本。有任何想法嗎..?
謝謝! 摹
function onOpen()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuItems = [{name: "Add Validation", functionName: "createNamedRangesAndVaidation"}]
ss.addMenu("Script", menuItems);
}
function createNamedRangesAndVaidation()
{
var ss, sheet, names, links, dataV, namesFlat, rule;
ss = SpreadsheetApp.getActiveSpreadsheet();
sheet = ss.getActiveSheet();
names = sheet.getRange("y:y").getValues();
dataV = sheet.getRange("a2");
namesFlat = []
for (var i = 1, length = names.length; i < length; i++)
{
if (!names[i][0]) break;
namesFlat.push(names[i][0]);
}
for (var j = 0, jlength = namesFlat.length; j < jlength; j++)
{
ss.setNamedRange(namesFlat[j], sheet.getRange(j+2, 26));
}
rule = SpreadsheetApp.newDataValidation().requireValueInList(namesFlat).build();
dataV.setDataValidation(rule);
}