Created
November 24, 2020 08:56
-
-
Save apivat60/e1b15de18c5bedc116f2b5524ca1edb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function submit() { | |
var ss = SpreadsheetApp.openByUrl('aaa') | |
var sheet = ss.getSheetByName('การตอบแบบฟอร์ม 1') | |
var range = sheet.getRange(sheet.getLastRow(), 2, 1, sheet.getLastColumn()) | |
var data = range.getDisplayValues() | |
var value0 ,value1,value2 | |
data.forEach(r=>{ | |
value0 = r[0] | |
value1 = r[1] | |
value2 = r[2] | |
}) | |
var tempFolder = DriveApp.getFolderById('aaa') | |
var templateSlide = DriveApp.getFileById('aaa') | |
var copyFile = templateSlide.makeCopy(value1, tempFolder) | |
var fileId = copyFile.getId() | |
var neno = SlidesApp.openById(fileId) | |
neno.replaceAllText('{{ชื่อ-สกุล}}', value1) | |
neno.replaceAllText('{{ลำดับที่}}', value2) | |
neno.saveAndClose() | |
var recipient = value0 | |
var subject = 'ส่งเกียรติบัตร' | |
var body = 'ยินดีกับท่านด้วยนะครับ' | |
var pdfFile = DriveApp.getFileById(fileId) | |
var pdf = pdfFile.getAs(MimeType.PDF) | |
var options = {attachments:[pdf]} | |
MailApp.sendEmail(recipient, subject, body, options) | |
tempFolder.removeFile(copyFile) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment