-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathchatGPTcode.gs
More file actions
46 lines (37 loc) · 1.47 KB
/
chatGPTcode.gs
File metadata and controls
46 lines (37 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function generateInvitationPDFs() {
// Get the active sheet
var sheet = SpreadsheetApp.getActiveSheet();
// Get the data range for the sheet
var dataRange = sheet.getDataRange();
// Get the values from the sheet
var data = dataRange.getValues();
// Loop through each row in the sheet
for (var i = 1; i < data.length; i++) {
// Get the current row
var row = data[i];
// Get the first name, last name, time, zoom link, and email
var firstName = row[0];
var lastName = row[1];
var time = row[2];
var zoomLink = row[3];
var email = row[4];
// Make a copy of the template document
var docId = DriveApp.getFileById("ID of Doc Template").makeCopy("Invitation from Learning Orbis").getId();
var doc = DocumentApp.openById(docId);
// Replace the placeholders in the document with the appropriate values
doc.getBody().replaceText("{{First}}", firstName);
doc.getBody().replaceText("{{Last}}", lastName);
doc.getBody().replaceText("{{Meeting Time}}", time);
doc.getBody().replaceText("{{Zoom Link}}", zoomLink);
doc.getBody().replaceText("{{Today}}", new Date().toLocaleDateString());
doc.saveAndClose()
// Save the document as a PDF
var pdf = doc.getAs("application/pdf");
// Send the PDF as an email attachment
GmailApp.sendEmail(email, "Invitation from Learning Orbis", "", {
attachments: [pdf]
});
// Delete the temporary document
DriveApp.getFileById(docId).setTrashed(true);
}
}