如何在同一张纸上制作四个不同的时间戳?

时间:2019-10-17 20:11:08

标签: google-apps-script google-sheets

我想基于标题为“时间戳1” /“时间戳2”的列在工作表中使用4个不同的时间戳。选中此框后,时间戳将移入序列列。这是我的第一张图表的脚本。如何在该页面上的所有四个图表上做到这一点? https://docs.google.com/spreadsheets/d/11AQMvhWbzgmLLPbdf94nW7D_Kkb1aQefrU755AOhkJo/edit?usp=sharing

function onEdit(event) {
  const timezone = 'GMT-5';
  const timestamp_format = 'HH:mm:ss'; // Timestamp Format.
  const updateColName = 'Time Stamp 1';
  const timeStampColName = 'Sequence 1';
  const sheet = event.source.getSheetByName('Experiment - Training w/ Duration'); // Name of the sheet where you want to run this script.
  const actRng = event.source.getActiveRange();
  const editColumn = actRng.getColumn();
  const index = actRng.getRowIndex();
  const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
  const dateCol = headers[0].indexOf(timeStampColName);
  let updateCol = headers[0].indexOf(updateColName); updateCol += 1;
  if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself!
    const cell = sheet.getRange(index, dateCol + 1);
    const date = Utilities.formatDate(new Date(), timezone, timestamp_format);
    cell.setValue(date);
  }
}

0 个答案:

没有答案