我正在尝试清除Google中的电子表格。 我正在使用以下代码,但似乎无法让它工作。按钮在那里,但它没有做任何事情,并给我错误,找不到menubutton。
var activeSS = SpreadsheetApp.getActiveSpreadsheet();
var activeSh = activeSS.getActiveSheet();
var menubuttons = [ {name: 'Clear Sheet', functionName: 'Clearsheet'},]
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Clear Sheet')
.addItem('Clear Sheet', 'menubuttons')
.addToUi();
}
function menubuttons() {
ss.addMenu('Clearsheet', 'menubuttons');
// note you also have to have functions called clearRange1 and clearRange2 as list below
function Clearsheet() { //replace 'Sheet1' with your actual sheet name
sheet.getRange('A7:I100').clearContent();
}
}
答案 0 :(得分:0)
我修好了!! - 那是在错误的路线上......花了几天时间搞清楚了!
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menubuttons = [ {name: "Clear Sheet", functionName: "clearRange1"},]
ss.addMenu("Clear Sheet", (menubuttons)) ;
}
function clearRange1() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
sheet.getRange('A8:I73').clearContent();
}