Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 在电子表格中切换工作表时,如何触发函数?_Google Apps Script_Google Sheets_Google Sheets Api_Google Workspace - Fatal编程技术网

Google apps script 在电子表格中切换工作表时,如何触发函数?

Google apps script 在电子表格中切换工作表时,如何触发函数?,google-apps-script,google-sheets,google-sheets-api,google-workspace,Google Apps Script,Google Sheets,Google Sheets Api,Google Workspace,切换工作表时如何触发功能?主要目标是跟踪人们如何使用电子表格。我发现以下选项正好可以做到这一点,但它只跟踪我在工作表之间切换的情况,而不跟踪其他人切换的情况: var PROP_NAME = "lastSheetIdx"; var userProperties = PropertiesService.getUserProperties(); function timedEventHandler() { var currentSheetIdx = SpreadsheetApp.getActi

切换工作表时如何触发功能?主要目标是跟踪人们如何使用电子表格。我发现以下选项正好可以做到这一点,但它只跟踪我在工作表之间切换的情况,而不跟踪其他人切换的情况:

var PROP_NAME = "lastSheetIdx";
var userProperties = PropertiesService.getUserProperties();

function timedEventHandler() {
  var currentSheetIdx = SpreadsheetApp.getActiveSheet().getIndex()
  var previousSheetIdx = parseInt(userProperties.getProperty(PROP_NAME));
  if (currentSheetIdx !== previousSheetIdx) {
    didSwitchSheets(previousSheetIdx, currentSheetIdx);
    userProperties.setProperty(PROP_NAME, currentSheetIdx);
  }
}

function didSwitchSheets(from, to) {
  var sheet =SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Engagement");
  Logger.log("Switched from " + from + " to " + to);
  sheet.appendRow([new Date(), to, Session.getActiveUser().getEmail()]);
}
有什么建议吗?我如何更改此脚本,以便它跟踪任何人(收到他们的电子邮件)在工作表之间切换


对于上下文,我们使用GSuite,因此我们可以提取相同域的电子邮件地址。

没有触发条件。如果必须这样做,是否值得运行客户端对话框,每隔几秒钟轮询一次电子表格?@cooper,我计划使用时间触发器,以便脚本每分钟运行一次。不是完美的,但在列表中我会得到一些数据。问题是,目前只为我工作,即。如果其他用户在工作表之间移动,他们不会被跟踪。不确定我需要更改什么,所以它们也会被跟踪。因此触发器将基于时间,脚本将每分钟运行一次。这并不理想,但当用户在工作表之间切换时,我看不到任何其他触发方式。如果您有任何想法,我将不胜感激@Cooper你能为“每隔几秒钟轮询一次的客户端对话框”提供一个例子吗?这对用户来说是不可见的吗?否则我将无法使用它。那么,我如何才能获得上一张表的名称而不是带有“lastSheetIdx”的索引?我在文档中找不到“lastSheetIdx”,是否有“lastSheetName”“?我想我会尝试使用可安装的onEdit触发器。构建您自己的触发器脚本,以便每个人都可以使用它,并在OneEdit中跟踪日志中的所有编辑,可以是电子表格,也可以是文本文件插入时间戳和来自e.range.getSheet()和带有e.range.geta1符号的范围的工作表,然后轮询该电子表格或日志文件。。。我会使用一个文件。