google-apps-script - 如何检测用户更改表?

标签 google-apps-script google-sheets

如何在电子表格中打开特定工作表时检测并触发自定义操作?

我在 https://developers.google.com/apps-script/guides/triggers/events 中找不到正确的功能

最佳答案

要按照 Mogsdad 的建议进行轮询,您可以在侧边栏(或任何 UI 元素)中使用此代码

$(function() {
   /**
   * On document load, assign click handlers to each button and try to load the
   * user's origin and destination language preferences if previously set.
   */
   poll();
}

function poll(interval){
    interval = interval || 2000;
    setTimeout(function(){
    google.script.run.withSuccessHandler(loadSheetName)
        .withFailureHandler(showError).getSheetName();
    poll();
    }, interval);
};

function loadSheetName(sheetName) {
   alert(sheetName);
   }

function getSheetName() {
   google.script.run.withSuccessHandler(loadSheetName)
        .withFailureHandler(showError).getSheetName();
   }

在你的 .gs 代码中

function getSheetName() {
var sheetName =         SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
return sheetName;
}

关于google-apps-script - 如何检测用户更改表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37703309/

相关文章:

javascript - 将数组组合为列而不是行的 Google Apps 脚本

python - 使用 OAuth 和 gdata 复制谷歌电子表格

google-apps-script - 如何在 onEdit 触发器上执行 copyTo 后附加时间戳?

google-apps-script - 使用 Google Apps 脚本获取 Google Drive 事件

javascript - 如何使用 Google App 脚本将一个 Google Sheet 中的所有数据拉到另一个 Google Sheet Tab 中?

google-apps-script - 如果尚不存在,请在云端硬盘中创建新文件夹

google-apps-script - 如何禁用 SpreadsheetApp.addMenu 项

google-sheets - 如果单元格包含某个范围内的字符串之一,则突出显示该单元格

if-statement - Google 表格 IF 语句与连接合并

javascript - 如何通过传递参数从 .gs 文件中的方法调用 "somename.html"?