我有一张多年的统计表;但是,我想隐藏未来年份以保持表格紧凑,直到需要这些年份为止。我有以下脚本,一次隐藏和显示一列,但我需要它一次隐藏两列。例如,在菜单点击时隐藏 T 和 U 列(而不是一次点击 T 和下一次点击 U )。
/** @OnlyCurrentDoc */
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Show Next Season')
.addItem('Hide Columns', 'hideCol')
.addItem("Show Columns", 'show')
.addToUi();
}
function hideCol() {
const sheet = SpreadsheetApp.getActive().getSheetByName('Season by Season'); //put the name of the sheet in place of 'Main'
const array = Array(sheet.getMaxColumns()-4).fill().map((element, index) => index + 20);
for(let col of array){
if(!sheet.isColumnHiddenByUser(col)){
sheet.hideColumns(col);
break;
}
}
}
function show() {
const sheet = SpreadsheetApp.getActive().getSheetByName('Season by Season'); //put the name of the sheet in place of 'Main'
const array = Array(sheet.getMaxColumns()-4).fill().map((element, index) => index + 20);
for(let col of array){
if(sheet.isColumnHiddenByUser(col)){
sheet.showColumns(col);
break;
}
}
}
上面的脚本一次只隐藏一列。我希望它一次隐藏两个。
这样试试:
hideColumns(20,2);