Google表格时间戳记(如果填写了多列)

时间:2019-03-21 11:06:47

标签: google-apps-script google-sheets google-sheets-macros

希望使用自动时间戳记

我正在处理一个脚本,该脚本在填充多(12)列时会自动添加时间戳:

链接到电子表格: https://docs.google.com/spreadsheets/d/17UHDExBkSJMNt2SiYRum64slI22x52YnZ12yeIjNaNs/edit?usp=sharing

这是我在Google App脚本上运行的代码:它未返回任何内容,似乎我惨败,请伸出援助之手!

function onEdit(event)
{
var timezone = "GMT-5";
var timestamp_format = "MM-dd-yyyy"; // Timestamp Format. 
var updateColName = "Link Type";
var updateColName1 = "Domain"; 
var updateColName2 = "URL"; 
var updateColName3 = "Anchor Text"; 
var updateColName4 = "Domain Authority Moz";  
var updateColName5 = "Page Authority Moz";  
var updateColName6 = "Trustflow Majestic SEO";
var updateColName7 = "Spam Score Moz";
var updateColName8 = "Link Score";
var updateColName9 = "Contact Name";
var updateColName10 = "Contact Email";
var updateColName11 = "Destination URL";    
var timeStampColName = "Prospector - TimeStamp";
var sheet = event.source.getSheetByName('OFF PAGE SEO');

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);

0 个答案:

没有答案