我有一些脚本,单独地,都可以工作。但是我无法让他们在打开表单时全部运行。目前,只有第一个脚本(hideColumn)在打开工作表时运行。从我设法创建的菜单中直接调用其他所有工作。
function onOpen() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// create menu
var menu = [{name: "Hide Overview Columns", functionName: "hideColumn"},
{name: "Hide Rebalancing Columns", functionName: "hideColumn2"},
{name: "Add/Hide Dividend Data for Chart", functionName: "hideColumn3"}];
// add to menu
ss.addMenu("Check", menu);
// execute function
function hideColumn(){
function hideColumn(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Overview");
// get data
var data = sheet.getDataRange();
// get number of columns
var lastCol = data.getLastColumn()+1;
Logger.log(lastCol);
// itterate through columns
for(var i=1; i<lastCol; i++) {
if(data.getCell(1, i).getValue() == 'HIDE') {
sheet.hideColumns(i);
}
}
}
function hideColumn2() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Rebalancing");
// get data
var data = sheet.getDataRange();
// get number of columns
var lastCol = data.getLastColumn()+1;
Logger.log(lastCol);
// itterate through columns
for(var i=1; i<lastCol; i++) {
if(data.getCell(2, i).getValue() == 'HIDE') {
sheet.hideColumns(i);
}
}
}
function showColumn3() {
// get active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Dividends - Calculations");
// get data
var data = sheet.getDataRange();
// get number of columns
var lastCol = data.getLastColumn();
// show all columns
sheet.showColumns(1, lastCol);
}
function hideColumn3() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Dividends - Calculations");
// get data
var data = sheet.getDataRange();
// get number of columns
var lastCol = data.getLastColumn()+1;
Logger.log(lastCol);
// itterate through columns
for(var i=1; i<lastCol; i++) {
if(data.getCell(1, i).getValue() == 'HIDE') {
sheet.hideColumns(i);
}
}
}}}
答案 0 :(得分:0)
我们可以提供帮助,但除非您告诉我们您尝试过,否则不会为您编码! 您最好的选择是查看Google Apps Script文档。
以下是您需要检查以执行脚本的页面(您会看到它已得到很好的解释)