【发布时间】:2021-04-21 02:22:16
【问题描述】:
我想将 Slack 中的信息发送到 Google 表格的新行中,并包含一个时间戳,指示该行的添加时间。
按照关于如何Send Information into a Google Sheet 的 Slack 说明,我已成功添加一行,但看不到如何发送时间戳。
我从 this Stackoverflow page 找到了一个 Google Apps 脚本,用于在编辑单元格时添加时间戳:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 1 ) { //checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
}
}
当我在 Google 电子表格中手动输入数据时,脚本会添加时间戳,但是当我从 Slack 添加新行时,不会出现时间戳。
This Stackoverflow post 是关于类似的问题。它解释了粘贴和编辑之间存在差异,所以我认为我的问题是相关的。但我仍然不明白要在上面的脚本中进行哪些确切的更改,我也无法在该页面上成功实现更正后的脚本。
谁能帮帮我
- 调整上面的脚本,这样当我从 Slack 添加一行时它就可以工作了;或
- 想出另一种方式从 Slack 发送时间戳作为该行数据的一部分?
谢谢!
【问题讨论】:
-
onEdit触发器不会被公式或脚本激活,只能由 用户 编辑。仅存在仅取决于您的方案的解决方法。
标签: google-apps-script google-sheets triggers timestamp slack