首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在谷歌电子表格中添加的新单元格上时间戳?

问如何在谷歌电子表格中添加的新单元格上时间戳?
EN

Web Applications用户
提问于 2019-06-25 16:45:59
回答 1查看 527关注 0票数 0

下面的代码通过编辑另一列在google中插入时间戳。然而,有一个问题我不知道如何解决。当我手动添加新行时,它成功地添加了时间戳,但我的网站中有一个html表单,它将数据发送到此工作表,即使添加了新行,google也不会创建时间戳!这有点奇怪,因为从概念上讲,当添加新行时,意味着在单元格中进行编辑,而google必须添加时间戳。如果有人能帮我解决这个问题,我将不胜感激。谢谢

代码语言:javascript
复制
function onEdit(event)
{ 
  var timezone = "GMT+8:30";
  var timestamp_format = "yyyy-MM-dd HH:mm:ss"; // Timestamp Format. 
  var updateColName = "date";
  var timeStampColName = "Date Sent";
  var sheet = event.source.getSheetByName('Attendance'); //Name of the sheet where you want to run this script.


  var actRng = event.source.getActiveRange();
  var editColumn = actRng.getColumn();
  var index = actRng.getRowIndex();
  var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
  var dateCol = headers[0].indexOf(timeStampColName);
  var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
  if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself!
    var cell = sheet.getRange(index, dateCol + 1);
    var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
    cell.setValue(date);
  }
}
EN

回答 1

Web Applications用户

回答已采纳

发布于 2019-06-25 16:57:20

页面原文内容由Web Applications提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://webapps.stackexchange.com/questions/131197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档