Google apps script 要在Google应用程序脚本中偏移到下一页的时间戳数据
我希望时间戳数据显示在另一张工作表中,而不是显示在单元格中。我不想使用.tocopy方法,因为数据可能会在活动工作表中被删除(存档);从工作表中删除数据时,时间戳数据应保留在下一个工作表中 下面的代码片段:Google apps script 要在Google应用程序脚本中偏移到下一页的时间戳数据,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我希望时间戳数据显示在另一张工作表中,而不是显示在单元格中。我不想使用.tocopy方法,因为数据可能会在活动工作表中被删除(存档);从工作表中删除数据时,时间戳数据应保留在下一个工作表中 下面的代码片段: function onEdit() { var s = SpreadsheetApp.getActiveSheet(); if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet var
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 1 ) { //checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
}
}
如果知道要输入日期的工作表的名称,只需获取该工作表的引用,然后设置值
var sheetToWriteTo = s.getSheetByName('sheetName');
sheetToWriteTo.getRange(put range here).setValue(new Date());