我创建了以下代码来运行手动脚本以在 Google 幻灯片演示文稿中的多个实例中更改日期。如果当天是星期一,则脚本将其更改为星期四。如果是星期四,则另一个脚本将其更改为星期一。
function futurebriefthurs() {
var currdate = new Date();
var daystochange = 3;
var newbriefday = new Date(currdate.getFullYear(), currdate.getMonth(), currdate.getDate() + daystochange);
var NextBrief = Utilities.formatDate(new Date(newbriefday), "GMT-7", "EEEEE");
var pattern = "\\b\\d{1,2}/\\d{1,2}/\\d{4}\\b";
var slides = SlidesApp.getActivePresentation().getSlides();
var slidesLength = slides.length;
for (var i = 0; i < slidesLength; i++) {
var shapes = slides[i].getShapes();
var shapesLength = shapes.length;
for (var j = 0; j < shapesLength; j++) {
if (shapes[j].getDescription() == "$NextBrief") {
var textRange = shapes[j].getText();
textRange.clear();
textRange.insertText(0, NextBrief);
}
}
}
}
function futurebriefmon() {
var currdate = new Date();
var daystochange = 4;
var newbriefday = new Date(currdate.getFullYear(), currdate.getMonth(), currdate.getDate() + daystochange);
var NextBrief = Utilities.formatDate(new Date(newbriefday), "GMT-7", "EEEEE");
var pattern = "\\b\\d{1,2}/\\d{1,2}/\\d{4}\\b";
var slides = SlidesApp.getActivePresentation().getSlides();
var slidesLength = slides.length;
for (var i = 0; i < slidesLength; i++) {
var shapes = slides[i].getShapes();
var shapesLength = shapes.length;
for (var j = 0; j < shapesLength; j++) {
if (shapes[j].getDescription() == "$NextBrief") {
var textRange = shapes[j].getText();
textRange.clear();
textRange.insertText(0, NextBrief);
}
}
}
}
我想做的是有一个脚本在打开演示文稿时运行,检查当天并自动进行相同的更改。我们在预定日期使用此演示文稿,因此将日期更改为星期一和星期四以外的日期的需要很少。
在某个时候,我希望能够根据 Google 日历条目进行更改,但那是另一天。:-)