我想创建2个按钮,以允许用户在Google电子表格中向后和向前滚动页面。我是Java和谷歌应用程序的新手,我的豌豆脑无法解决问题。这是我的代码。欢迎任何更正/建议,因为它目前无法正常工作。
function nextSheet (){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getActiveSheet().getIndex();
var num = sheet +1;
SpreadsheetApp.setActiveSheet(ss.getSheets()[num]);
}
function prevSheet(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var num = (sheet.getIndex())-1;
SpreadsheetApp.setActiveSheet(ss.getSheets()[num]);
}
答案 0 :(得分:1)
function nextSheet (){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getActiveSheet().getIndex();
var num = sheet +1;
SpreadsheetApp.setActiveSheet(ss.getSheets()[num-1]);
}
getIndex()从1开始(从1开始),但数组基于0。这就是问题。如上所述,将[num]更改为[num-1],它将起作用。