首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不在星期天运行脚本

不在星期天运行脚本
EN

Stack Overflow用户
提问于 2018-12-05 10:01:19
回答 1查看 148关注 0票数 1

我有一个在Google Sheets的日常触发器上运行的脚本,从一个电子表格中提取数据并将其存储在另一个电子表格中。

它工作得很好,但我需要它不在星期天运行。我不太清楚如何验证日期,只在周一到周六运行脚本。

代码语言:javascript
运行
复制
    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);

}

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-12-05 10:12:40

一种方法是使用Installable Trigger。手动设置6个带有周计时器的时间驱动触发器,周一至周六每天一个。

另一种方法是手动设置1个每天运行的时间驱动触发器,但检查脚本是否为星期天

代码语言:javascript
运行
复制
var currentDay = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "E");
if (currentDay !== "Sun") {
    // execute the rest of the code
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53624085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档