当文件与任何有链接的人共享时,Google脚本不会执行

时间:2015-04-23 19:04:47

标签: google-apps-script google-sheets google-spreadsheet-api

在未登录的用户打开Goog​​le工作表时执行App脚本时出现问题。任何有链接的人都可以设置电子表格。如果用户已登录,则脚本按预期工作。

这是我的应用程序。脚本:

/**  A special function that runs when the spreadsheet is open */

function onOpen() {
// Display a dialog box with a title, message, input field, and "Ok" and "Cancel" buttons. The
 // user can also close the dialog by clicking the close button in its title bar.
 var ui = SpreadsheetApp.getUi();
 var response = ui.prompt('Update Listing', 'Please enter the tournament date as mm/dd', ui.ButtonSet.OK_CANCEL);

 // Process the user's response.
 if (response.getSelectedButton() == ui.Button.OK) {
  SpreadsheetApp.getActiveSheet().getRange('B1').setValue( response.getResponseText());
 } else if (response.getSelectedButton() == ui.Button.CANCEL) {
   Logger.log('The user didn\'t want to provide a date.');
 } else {
   Logger.log('The user clicked the close button in the dialog\'s title bar.');
 }
}

1 个答案:

答案 0 :(得分:0)

这是因为虽然用户在未登录时可以访问和编辑工作表,但只有用户登录时才能访问/编辑/运行脚本。不幸的是,应用程序脚本的功能不可扩展对于未登录的用户。