每当我更新列F(注释)时,我的脚本已经为我的列H(调用时间)加上时间戳:
function onEdit(event)
{
var timezone = "GMT-7";
var timestamp_format = "MM-dd-yyyy HH:mm:ss"; // Timestamp Format.
var updateColName = "Notes";
var timeStampColName = "Call Time";
var sheet = event.source.getSheetByName('Today'); //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);
}
}
现在我需要在我的专栏F(CB日期)上的未来时间戳(从现在起3周)。
这可能吗?
答案 0 :(得分:0)
还有一些其他方面可以对代码进行一些改进,但要解决您的具体要求:
function onEdit(event)
{
var timezone = "GMT-7";
var timestamp_format = "MM-dd-yyyy HH:mm:ss"; // Timestamp Format.
var updateColName = "Notes";
var timeStampColName = "Call Time";
var cbDateColName = "CB Date";
var sheet = event.source.getSheetByName('Today'); //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 cbcell = sheet.getRange(index, headers[0].indexOf(cbDateColName) + 1);
var d = new Date();
var cbd = new Date(d.getTime() + 3*7*24*60*60*1000);
var date = Utilities.formatDate(d, timezone, timestamp_format);
var cbdate = Utilities.formatDate(cbd, timezone, timestamp_format);
cell.setValue(date);
cbcell.setValue(cbdate);
}
}