以下脚本使我每次在A栏上填充一个单元格时都能获得C栏的时间戳。
如果再次更改列中的单元格,则很遗憾时间戳会更新。我只想要第一次填充该单元格的时间戳。
我应该如何进行?
`function onEdit(event)
{
var timezone = "GMT+1";
var timestamp_format = "MM-dd-yyyy HH:mm:ss"; // Timestamp Format.
var updateColName = "A";
var timeStampColName = "C";
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Feuille_1'); //Name of the sheet where you want to run this script.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Feuille_2'); //Name of the sheet where you want to run this script.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Feuille_3'); //Name of the sheet where you want to run this script.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Feuille_4'); //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);
}
}