function updateBirthdaySlide() {
// ======================================================
// CONFIGURATION SECTION - PASTE YOUR IDs HERE
// ======================================================
var slideId = 'Google Slide的 ID';
var sheetId = 'Google Sheet 的 ID';
var sheetName = 'Sheet1'; // Change if your tab has a different name
// ======================================================
// 1. Get the Data from the Sheet
var ss = SpreadsheetApp.openById(sheetId);
var sheet = ss.getSheetByName(sheetName);
var data = sheet.getDataRange().getValues();
// 2. Get Today's Date
var today = new Date();
var currentMonth = today.getMonth(); // Note: January is 0 in JavaScript
var currentDay = today.getDate();
var birthdayNames = [];
// 3. Loop through the rows (Starting from row 1 to skip headers)
for (var i = 1; i < data.length; i++) {
var name = data[i][0];
var birthday = new Date(data[i][1]);
// Check if the date is valid, then match Month and Day
if (birthday && birthday.getMonth() === currentMonth && birthday.getDate() === currentDay) {
birthdayNames.push(name);
}
}
// 4. Create the display message in bullet form
var displayText = "";
if (birthdayNames.length > 0) {
// This creates a list where each name starts with a bullet point
displayText = "🎉 某某某华小衷心祝福 Happy Birthday to:\n\n" + birthdayNames.map(function(name) {
return "• " + name;
}).join("\n") + "\n\n🎂 校方希望对学生说的祝福语";
} else {
displayText = "若当天没有学生生日的话,会出现的字眼";
}
// 5. Update the Google Slide
var deck = SlidesApp.openById(slideId);
var slides = deck.getSlides();
var slide = slides[0]; // Gets the first slide
var shapes = slide.getShapes();
// Find the text box tagged as "BirthdayBox" and update it
for (var j = 0; j < shapes.length; j++) {
if (shapes[j].getTitle() === "BirthdayBox") {
shapes[j].getText().setText(displayText);
}
}
}