我有一个脚本可以在Google表格中的每日触发器上运行,可以从一个电子表格中提取数据并将其存储在另一个电子表格中。
它的运行很棒,但是我需要它不能在周日运行。我不太清楚如何验证日期,而只在星期一至星期六运行脚本。
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);
}
谢谢!
答案 0 :(得分:1)
一种方法是使用Installable Trigger。手动将其设置为6个时间驱动的触发器,并带有星期计时器,周一至周六每天设置一个。
另一种方法是将其手动设置为每天运行一次时间驱动的触发器,但是请检查脚本是否为星期日
var currentDay = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "E");
if (currentDay !== "Sun") {
// execute the rest of the code
}