Skip to content

Commit 8477ff8

Browse files
committed
main.gs: created & refined -- untested
1 parent e11deb2 commit 8477ff8

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

main.gs.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Assumptions
2+
// 1. The sheet with the students is called Sheet1
3+
// 2. The certificate name placeholder is 'Name PlaceHolder'
4+
5+
var studentsId = "16FCTdyJ2ONyXPZvm6fn_o8KP6zjDlSyThXrvpMrrnVU";
6+
var sheetName = "Sheet1";
7+
var namePlaceholder = "Name PlaceHolder";
8+
var courses = [
9+
{
10+
name: "Web App Development with PHP & MySQL",
11+
slides: "1ZQCC-o1f_29U6YLpaE2wpsCBkE-HpD8Ka83hiAdGNh0",
12+
},
13+
{
14+
name: "Web App Development with PHP & MySQL",
15+
slides: "1ZQCC-o1f_29U6YLpaE2wpsCBkE-HpD8Ka83hiAdGNh0",
16+
},
17+
];
18+
19+
function main() {
20+
const getByName = (colName, sheetName, id) => {
21+
var sheet = SpreadsheetApp.openById(id).getSheetByName(sheetName);
22+
var data = sheet.getRange("A1:1").getValues();
23+
var col = data[0].indexOf(colName);
24+
if (col != -1) {
25+
var unfiltered = sheet.getRange(2, col + 1, sheet.getMaxRows()).getValues();
26+
var arrFiltered = unfiltered.filter(function (x) {
27+
return !x.every((element) => element === (undefined || null || ""));
28+
});
29+
return arrFiltered.filter(function (x) {
30+
return x.toString();
31+
});
32+
}
33+
};
34+
35+
const duplicateSlides = (certSlide, students) => {
36+
certSlide.forEach(function (slide) {
37+
for (let i = 1; i < students.length; i++) {
38+
slide.duplicate();
39+
}
40+
});
41+
};
42+
43+
const fillData = (certs, students) => {
44+
for (var i = 0; i < students.length; i++) {
45+
var student = students[i].toString();
46+
var shapes = certs[i].getShapes();
47+
shapes.forEach(function (shape) {
48+
shape.getText().replaceAllText(namePlaceholder, student);
49+
});
50+
}
51+
};
52+
53+
for (const course of courses) {
54+
let certs = SlidesApp.openById(course.slides).getSlides();
55+
let students = getByName(course.name, sheetName, studentsId);
56+
duplicateSlides(certs, students);
57+
fillData(certs, students);
58+
}
59+
}

0 commit comments

Comments
 (0)