Documentation on this code

84 views
Skip to first unread message

Scott Bennett

unread,
Mar 22, 2021, 2:52:48 PM3/22/21
to Google Apps Script Community
Hello,
I found this code online and it works great.  Can anyone tell me where there is documentation on this type of code?  I am really unsure where to look.  I would like to learn more about it.  I have never seen the export options listed here.
function emailSpreadsheetAsPDF() {
  DocumentApp.getActiveDocument();
  DriveApp.getFiles();


  const ss = SpreadsheetApp.openByUrl("sheetURL");
  const email = 'email'

  // Subject of the email message
  const subject = 'Roster';

  // Email Text. You can add HTML code here - see ctrlq.org/html-mail
  const body = "Here is our roster";

  // Again, the URL to your spreadsheet but now with "/export" at the end
  // Change it to the link of your spreadsheet, but leave the "/export"
  const url = 'SheetURL/export?';

  const exportOptions =
    'exportFormat=pdf&format=pdf' + // export as pdf
    '&size=letter' + // paper size letter / You can use A4 or legal
    '&portrait=true' + // orientation portal, use false for landscape
    '&fitw=false' + // fit to page width false, to get the actual size
    '&sheetnames=false&printtitle=false' + // hide optional headers and footers
    '&pagenumbers=false&gridlines=true' + // hide page numbers and gridlines
    '&fzr=true' + // do not repeat row headers (frozen rows) on each page
    '&gid=1507185252'// the sheet's Id. Change it to your sheet ID.
  // You can find the sheet ID in the link bar. 
  // Select the sheet that you want to print and check the link,
  // the gid number of the sheet is on the end of your link.
  
  var params = {method:"GET",headers:{"authorization":"Bearer "ScriptApp.getOAuthToken()}};
  
  // Generate the PDF file
  var response = UrlFetchApp.fetch(url+exportOptionsparams).getBlob();
  
  // Send the PDF file as an attachement 
    GmailApp.sendEmail(emailsubjectbody, {
      htmlBodybody,
      attachments: [{
            fileName"List" + ".pdf",
            contentresponse.getBytes(),
            mimeType"application/pdf"
        }]
    });

  // Save the PDF to Drive. The name of the PDF is going to be the name of the Company (cell B5)
  const nameFile = "Ticket List" +".pdf"
  DriveApp.createFile(response.setName(nameFile));


Thanks

Bruce Mcpherson

unread,
Mar 22, 2021, 3:07:13 PM3/22/21
to google-apps-sc...@googlegroups.com

This example uses the same technique to convert files and move them to Microsoft one drive.

Drive files, have metadata that points to links that export to various

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a20599eb-6884-4ed5-85e5-2755654c8ea5o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages