如何让Google Sheet Apps脚本为具有编辑权限的所有用户运行onOpen功能

时间:2018-06-14 23:57:41

标签: google-apps-script google-sheets triggers

我有一个显示方向的弹出框,但它只显示我打开工作表的时间。我想让它在任何有权访问它的用户打开时运行。只是为了澄清,其他用户都是编辑。

我的toast框确实显示给其他用户,但html应用程序没有

这是我的剧本:

    function onOpen() {
      var message = "Let's have a productive day!";
      var title = 'Welcome Back Greeter';+
      SpreadsheetApp.getActiveSpreadsheet().toast(message, title, 10);


      var htmlApp = HtmlService
         .createHtmlOutput('<p>Make sure you mark the following each time a plate is taken or returned: </p>----Salesperson Name </p>----Time Out </p>----Time In </p>----and if it is Pupped! </p>Do not let Salespeople take plates themselves! </p>As Greeters we are responsible for tracking these plates. This sheet is going to be reviewed with Bob each night with a list of which plates are out for the night as well as a list of the plates that are currently in their folders for the next day. </p> Sincerely, The Plate Fairy</p>')
         .setTitle('!!!!!  ATTENTION GREETER  !!!!!')
         .setWidth(350)
         .setHeight(400);

      SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
    }

2 个答案:

答案 0 :(得分:1)

用户必须授予您的脚本打开对话框的权限。因此,您需要让他们创建一个他们将授权的installable onOpen trigger,并在随后的打开时显示您的对话框。

你无法强制他们这样做,你只能为他们提供类似自定义菜单选项的选项。

答案 1 :(得分:0)

仅当文档(在本例中为电子表格)由所有者或编辑者打开时才会触发简单触发器。另一方面,简单的触发器有几个限制,比如它们不能打开对话框,侧边栏等等。

有关详细信息,请参阅Simple Triggers

值得注意的是,目前存在一些可能与此主题相关的未解决问题。我已经在"You do not have permission to call showModalDialog"

的回答中提到过它们