I'm trying to save my results into PDF file after google sheet calculation. Here's my google sheet file: Google sheet(img)
After someone submit my form J Column sum all answers and gets 39. Then I want to convert my template file template(img) to PDF, so I wrote this code:
function afterFormSubmit(e) {
Logger.log(JSON.stringify(e));
var formValues = e.namedValues;
Logger.log(formValues);
const info = e.namedValues;
createPDF(info);
}
function createPDF(info){
const pdfFolder = DriveApp.getFolderById("1YPyX8gv3W-JXR0uovMdr");
const tempFolder = DriveApp.getFolderById("1m9Xcc9hmhJjc83cSgCW26u");
const templateDoc = DriveApp.getFileById("1r4m3-FtzMzlO_SmGMPuGraJhEIBsQA");
const newTempFile = templateDoc.makeCopy(tempFolder);
const openDoc = DocumentApp.openById(newTempFile.getId())
const body = openDoc.getBody();
body.replaceText("{T}", info['Timestamp'][0]);
body.replaceText("{A2}" ,info['answer2'][0]);
body.replaceText("{A3}" ,info['answer3'][0]);
body.replaceText("{A4}" ,info['answer4'][0]);
body.replaceText("{A5}" ,info['answer5'][0]);
body.replaceText("{A6}" ,info['answer6'][0]);
body.replaceText("{A7}" ,info['answer7'][0]);
body.replaceText("{E}", info['Email'][0]);
body.replaceText("{R}" ,info['Results'][0]); //Please fix it: PDF Not showing/Saving Results
openDoc.saveAndClose();
const blobPDF = newTempFile.getAs(MimeType.PDF);
const pdfFile = pdfFolder.createFile(blobPDF).setName("Quiz finish time:"+" "+ info['Timestamp'][0]);
tempFolder.removeFile(newTempFile);
}
But when this code converts my template file to PDF he don't show/save my result {R} PDF(img), but all other body.replaceText(); works well. Maybe someone know how to deal with that (how to save/show Result into PDF file)?