【发布时间】:2017-09-11 18:28:32
【问题描述】:
尝试向我的电子表格添加自动时间戳。任何时候在“PM 状态”列中编辑数据时,我都希望在“日期更新”列中有一个自动时间戳。
function onEdit(event)
{
var timezone = "ET";
var timestamp_format = "MM-dd-yyyy"; // Timestamp Format.
var updateColName = "PM Status";
var timeStampColName = "Date Update";
var sheet = event.source.getSheetByName('All Leads'); //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);
}
}
【问题讨论】:
标签: google-apps-script google-sheets timestamp