我确信这是我的错误,但由于脚本可以正常工作,所以不确定这是否会在某个时候出现。我有 11 个选项卡,脚本会遍历前 9 个选项卡并隐藏所有没有数据的行,然后将每个选项卡的光标设置为 B4,但第 10 和 11 个选项卡除外,它们将设置为 A1。但是有一个红色的花括号,我不知道如何更正它。一个位于第一行末尾,对应的是带有 }); 的行。感谢您的帮助。
function onOpen() {
SpreadsheetApp.getActive().getSheets().forEach(function (s,index,array) { //for each sheet
if(index<9){ //if sortable page, not maps or docs
var nameOfSheet= array[index].getName()
var ssa = SpreadsheetApp.getActive().getSheetByName(nameOfSheet) //get active sheet
var max = ssa.getMaxRows()//max rows for this sheet
var last = ssa.getLastRow() //last row with data
ssa.hideRows(last+1, max-last)
}
if(index>8){
s.setActiveSelection("A1"); //set active cell for sheet to A1 if map or documentation sheet
SpreadsheetApp.flush(); // Force this update to happen before moving to next sheet
}else{
s.setActiveSelection("B4"); //set active cell for sheet to B4 for other sheets
SpreadsheetApp.flush(); // Force this update to happen before moving to next sheet
}
});
var sheet = SpreadsheetApp.getActive().getSheetByName('Active(Date)'); //set back to first sheet
var range = sheet.getRange('B4'); //put cursor on search box
range.activate();
}
Monaco 编辑器会用红色高亮来标明代码缺少正确的缩进。代码可能运行良好,语义也正确,但不正常的缩进会让阅读代码时难以理解逻辑。
要正确缩进代码,请按Control+Shift+I (Windows) 或⇧⌥F (macOS),或右键单击以显示上下文菜单,然后选择“格式化文档”。要查看编辑器命令和键盘快捷键,请按F1。
问题中引用的代码可以简化并正确缩进,如下所示:
参考