【问题标题】:Google Sheet Script - add date in colum before the copiedGoogle Sheet Script - 在复制之前在列中添加日期
【发布时间】:2020-06-09 10:31:33
【问题描述】:

我在 google 工作表中使用以下处理从源工作表上的一行复制一系列值。 它将它作为从第二列开始的值附加到目标工作表。 这工作正常,但我现在想在第 1 列添加脚本运行的日期/时间“localDateTime”,但我只是不知道如何完成。

有人可以帮忙吗

function copyInfo() {
  // get date & time
  var localDateTime = new Date()
  // other variables
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var copySheet = ss.getSheetByName("Performance");
  var pasteSheet = ss.getSheetByName("PortfolioTrend");

  // get source range
  // getRange(row, column, numRows, numColumns)
  var source = copySheet.getRange(103,5,1,7);

  // get destination range
  var destination = pasteSheet.getRange(pasteSheet.getLastRow()+1,+2,1,7);


  // copy values to destination range
  source.copyTo(destination, {contentsOnly:true});

}

【问题讨论】:

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


    【解决方案1】:

    我相信你的目标如下。

    • 您希望将localDateTime 的值放在destination 第一列的左侧。

    对于这个,这个修改怎么样?

    发件人:

    source.copyTo(destination, {contentsOnly:true});
    

    收件人:

    source.copyTo(destination, {contentsOnly:true});
    destination.offset(0, -1, 1, 1).setValue(localDateTime);  // Added
    

    参考:

    【讨论】:

    • @Marco 欢迎。谢谢你让我知道。我很高兴你的问题得到了解决。如果您的问题得到解决,请按接受按钮。与您有相同问题的其他人也可以将您的问题作为可以解决的问题。我认为您的问题和解决方案将对他们有用。如果找不到按钮,请随时告诉我。 stackoverflow.com/help/accepted-answer
    • 你好田池。谢谢你教育我接受功能。我找到并使用了它。非常感谢。
    • @Marco 感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 2017-01-25
    相关资源
    最近更新 更多