2

我有一段代码可以在我的谷歌表格中的任何编辑上运行,如下所示:

function onEdit(e) {
   Browser.msgBox("I pop up on Edit!");
}

但是,当它作为附加组件部署并发布到 Chrome 网上应用店时,它似乎不起作用......我在其他不涉及编辑触发器的方法中有 Browser.msgBox,它们工作正常。

我曾尝试使用模态对话框、ui 警报、注释、html 弹出窗口和 toast 消息来代替 Browser.msgBox,但它们在编辑触发器功能中都不起作用。

我能找到的唯一原因是编辑触发器与 Google 电子表格插件中的弹出框不兼容。我可以对此有所了解吗?

4

2 回答 2

0

这是一个样本。

function onEdit(e){
  var ui = SpreadsheetApp.getUi();
  ui.alert("I pop up on Edit! " + e.value);
}

在此处输入图像描述

如果您想了解详细信息,请查看https://developers.google.com/apps-script/reference/base/ui

于 2017-03-08T21:58:55.543 回答
0

onEdit() will keep triggering when you're working in the sheet where you started your script (where it has been bound), but if you try deploying it as a Sheet add-on, you'll need to explicitly install it as a trigger. Note that it must still be named onEdit, not myEditingFunction.

In order to test your triggering functionality, you must first deploy your Sheet add-on as some sort of restricted app (to bypass Google's review) and deploy it to a sheet outside your test sheets, otherwise your trigger installation will cause exceptions: Exception: The Add-on attempted an action that is not permitted in Test as Add-on mode. To use this action, you must deploy the Add-on.

Here's the way I was installing my onEdit triggers:

var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
var documentProperties = PropertiesService.getDocumentProperties();
var editingFlag = documentProperties.getProperty(TRIGGER);
if (editingFlag == null) {
    try {
        trigger = ScriptApp.newTrigger("onEdit").forSpreadsheet(e.source).onEdit().create();
        documentProperties.setProperty(TRIGGER, "");
    } catch (e) {
        console.error("Caught exception on attempting to save trigger:" + e);
    }
} else {
    console.log("onEdit trigger is already listening for edits to sheet " + sheetName);
}
于 2018-07-17T05:00:59.460 回答