How to Create a PDF and Email from Sheet data using Google Apps Script code lesson

How to Create a PDF and Email from Sheet data using Google Apps Script code lesson

Generate a PDF document on the fly and send that document as an attachment to an email with all the data coming from a spreadsheet. Standalone script connecting to a spreadsheet for data and updating the selected spreadsheet.

  1. Get the ID of your spreadsheet that contains the data.
  2. Use the id and open the sheet by the id. SpreadsheetApp.openById(id);
  3. Select the sheet in the spreadsheet with the data you want, get the values without the headings as an array of rows.
  4. Loop through the rows of data, using the data from the Spreadsheet to create some HTML code.
  5. Use the Apps Script Utilities to create a blob of the html content. Utilities.newBlob(html,MimeType.HTML);
  6. Set a name for the blob. blob.setName(`${row[0]} ${row[1]}.pdf`);
  7. Get the email address, subject to send the PDF to.
  8. Using MailApp send an email to the user, with html for the body and subject. Using the attachments property in the email add the blob of PDF. attachments:[blob.getAs(MimeType.PDF)]
  9. Update the spreadsheet row data with a value that the PDF was sent.
  10. Check the inbox for the PDF and the email.

Related Posts

Leave a Reply

%d bloggers like this: