Create This Month Sheet
(创建本月表)
The code:
(代码:)
function createThisMonth() {
var ss=SpreadsheetApp.getActive();
var shn=Utilities.formatDate(new Date(),Session.getScriptTimeZone() ,"MMM-yyyy");
var sh=ss.getSheetByName(shn);
if(!sh) {
var sh=ss.insertSheet(shn,0);
}
var dA=[];
var cA=[];
var days=parseInt(Utilities.formatDate(new Date(new Date().getFullYear(),new Date().getMonth()+1,new Date().getDate()-1), Session.getScriptTimeZone(), "d"));
for(var d=1;d<=days;d++) {
var c1=Utilities.formatDate(new Date(new Date().getFullYear(),new Date().getMonth(),d),Session.getScriptTimeZone() , "d-MMM-yyyy");
var c2=Utilities.formatDate(new Date(new Date().getFullYear(),new Date().getMonth(),d),Session.getScriptTimeZone() , "E");
var c9=Utilities.formatDate(new Date(new Date().getFullYear(),new Date().getMonth(),d),Session.getScriptTimeZone() , "HH:mm:ss");
dA.push([c1,c2,0,0,0,0,0,0,c9,'']);
cA.push(['#ffffff','#ffffff','#ffff00','#ffff00','#ffff00','#ffff00','#ffff00','#ffff00','#00ff00','#ff0000']);
}
sh.getRange(1,1,dA.length,dA[0].length).setValues(dA);
sh.getRange(1,1,dA.length,dA[0].length).setBackgrounds(cA);
}
Run this to create trigger:
(运行此命令以创建触发器:)
function createTriggerForcreateTheMonth() {
if(!isTrigger('createThisMonth')) {
ScriptApp.newTrigger('createThisMonth').timeBased().onMonthDay(1).atHour(1).create();
}
}
Helper function:
(辅助功能:)
function isTrigger(funcName){
var r=false;
if(funcName){
var allTriggers=ScriptApp.getProjectTriggers();
for(var i=0;i<allTriggers.length;i++){
if(funcName==allTriggers[i].getHandlerFunction()){
r=true;
break;
}
}
}
return r;
}
The Sheet:
(工作表:)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…