Google apps script 谷歌电子表格脚本;切换";隐藏/查看列/行
我知道使用这些函数可以显示和隐藏列:Google apps script 谷歌电子表格脚本;切换";隐藏/查看列/行,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我知道使用这些函数可以显示和隐藏列: function showColumns() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getActiveSheet(); sheet.showColumns(2,3); // B-D, three columns starting from 2nd sheet.showColumn(7); // G, column number 7 }
function showColumns() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
sheet.showColumns(2,3); // B-D, three columns starting from 2nd
sheet.showColumn(7); // G, column number 7
}
function hideColumns() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
sheet.hideColumns(2,3); // B-D, three columns starting from 2nd
sheet.hideColumn(7); // G, column 7
}
但是,我需要两个按钮或菜单脚本,一个用于隐藏,一个用于显示列
我想知道是否存在“切换”功能,这样我就可以在不需要两个按钮或菜单项的情况下激活隐藏/显示功能。我看不到用脚本检测列的隐藏/未隐藏状态的方法,但切换行为可以通过将状态存储在中来实现。下面是管理属性并根据需要调用其他两个函数之一的函数
function toggleColumns() {
var scriptProperties = PropertiesService.getScriptProperties();
if (scriptProperties.getProperty('hidden')) {
showColumns();
scriptProperties.setProperty('hidden', false);
}
else {
hideColumns();
scriptProperties.setProperty('hidden', true);
}
}
这不起作用,因为所有属性都存储为字符串,即false存储为“false”,这是真的!所以我们最好使用字符串比较。