我有一个在Google Sheets的日常触发器上运行的脚本,从一个电子表格中提取数据并将其存储在另一个电子表格中。
它工作得很好,但我需要它不在星期天运行。我不太清楚如何验证日期,只在周一到周六运行脚本。
function copyDailyreport() {
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MSM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
//convert the column to a row
valuesToCopy=valuesToCopy.join('*#*');
valuesToCopy=valuesToCopy.split('*#*');
//add timestamp in the first place in the row
valuesToCopy.unshift(timeStamp)
//add the row to destination sheet
sheetTo.appendRow(valuesToCopy);
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SM");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SM Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
//convert the column to a row
valuesToCopy=valuesToCopy.join('*#*');
valuesToCopy=valuesToCopy.split('*#*');
//add timestamp in the first place in the row
valuesToCopy.unshift(timeStamp)
//add the row to destination sheet
sheetTo.appendRow(valuesToCopy);
var timeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SH");
var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SH Daily Totals");
var valuesToCopy = sheetFrom.getRange(4, 11, sheetFrom.getLastRow(), 1).getValues();
//convert the column to a row
valuesToCopy=valuesToCopy.join('*#*');
valuesToCopy=valuesToCopy.split('*#*');
//add timestamp in the first place in the row
valuesToCopy.unshift(timeStamp)
//add the row to destination sheet
sheetTo.appendRow(valuesToCopy);
}
谢谢!
发布于 2018-12-05 10:12:40
一种方法是使用Installable Trigger。手动设置6个带有周计时器的时间驱动触发器,周一至周六每天一个。
另一种方法是手动设置1个每天运行的时间驱动触发器,但检查脚本是否为星期天
var currentDay = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "E");
if (currentDay !== "Sun") {
// execute the rest of the code
}
https://stackoverflow.com/questions/53624085
复制相似问题