Google apps script Google应用程序脚本插入行代码不再使用具有保护集的新工作表
我已经使用下面的代码4年了,现在没有问题。然而,随着谷歌新表单的介绍,我发现以下错误: 遇到错误:服务错误:电子表格 我应该补充一点,除了用户可以插入行的行范围之外,我已经保护了整个工作表。其他地方都受到保护 如果工作表未受保护,该功能将100%工作 这是我的密码:Google apps script Google应用程序脚本插入行代码不再使用具有保护集的新工作表,google-apps-script,Google Apps Script,我已经使用下面的代码4年了,现在没有问题。然而,随着谷歌新表单的介绍,我发现以下错误: 遇到错误:服务错误:电子表格 我应该补充一点,除了用户可以插入行的行范围之外,我已经保护了整个工作表。其他地方都受到保护 如果工作表未受保护,该功能将100%工作 这是我的密码: //INSERT ROWS //Function doGet(): Creates and sets up a User Interface (UI) with a pop-up box for user to enter der
//INSERT ROWS
//Function doGet(): Creates and sets up a User Interface (UI) with a pop-up box for user to enter dersired number of rows to insert.
function doGet(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var app =UiApp.createApplication().setTitle('Insert Rows').setHeight(120).setWidth(250);
// Create a grid with text box and corresponding labels.
// Text entered into the text box is passed in to numRows.
// The setName extension will make the widget available by the given name to the server handlers later.
var grid = app.createGrid(3, 2);
grid.setWidget(0, 0, app.createLabel('Number of Rows to Insert:'));
grid.setWidget(0, 1, app.createTextBox().setName('numRows').setFocus(true).setWidth(50));
grid.setWidget(1, 0, app.createLabel('Maximum 1000 Rows'));
grid.setWidget(2, 0, app.createLabel(''));
// Create a Vertical Panel and add the Grid to the Panel.
var panel = app.createVerticalPanel();
panel.add(grid);
// Create a button and Click Handler.
// Pass in the Grid Object as a callback element and the handler as a click handler.
// Identify the function insertRows as the server click handler.
var button = app.createButton('Insert Rows');
var handler = app.createServerHandler('insertRows');
handler.addCallbackElement(grid);
button.addClickHandler(handler);
// Add the button to the Panel, add Panel to the App, launch the App
panel.add(button);
app.add(panel);
ss.show(app);
}
//Function insertRows(e): Makes the current Spreadsheet and Sheet active.
//Fetches the number of rows from the UI.
//Determines the current cursor position.
//Defines the hidden column range.
//Unhides the protected columns.
//Inserts the desired number of rows below the current cursor position.
function insertRows(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cursPos = sheet.getActiveCell().getRow();
var valueRows = e.parameter.numRows;
var lastColumn = sheet.getLastColumn();
sheet.insertRowsAfter(cursPos, valueRows);
//Defines the source range for data to be copied to the newly inserted rows.
//Defnies the target range for where the source data is to be copied.
//Copies the source data into the target data range.
//Hides the protected columns.
var source_range = sheet.getRange(cursPos,1,1,lastColumn);
var target_range = sheet.getRange(cursPos+1,1,valueRows);
source_range.copyTo(target_range);
//Closes the UI application and hands the spreadsheet back to the user.
SpreadsheetApp.getActiveSpreadsheet().toast("...Completed", "Insert Rows:", 3);
var app = UiApp.getActiveApplication();
app.close();
return app;
}
谢谢。
createGrid
已被弃用,您需要切换到HTMLService
好的,谢谢。。。但是,脚本在未受保护的工作表中100%工作。我很感激我需要在折旧后的服务不再可用之前转移到HTML服务。但我需要知道为什么服务没有在受保护的工作表中运行?好的,我删除了createGrid UI函数,并将其替换为“var numRows=Browser.inputBox('插入行','输入要插入的行数','浏览器.Buttons.OK_取消);'其中numRows变量成为光标位置下方要插入的行数。我仍然得到同样的错误。。。