title: setName when exporting a PDF from Google Sheets with Google Apps Script
body: <p>I have this script to export three separate sheets as PDF's using Google Apps Script which works fine except for the fact that the PDF's are exported with the file name of export.pdf in each case. I would like to rename them to 'Yesterday', 'Last 7 Days' and 'Last 30 Days' respectively, can anyone help me to achieve this, please?</p>
  <pre><code>//Menu in Google Sheet
  
  function onOpen() {
  
   var ui = SpreadsheetApp.getUi();
  
   ui.createMenu('Dashboard')
  
     .addItem('Email Dashboard','emailDashboard')
  
     .addToUi();
  
  }
  
  //Convert dashboard to PDF and email a copy to user
  function emailDashboard() {
  
   // get sheet id
  
   var ss = SpreadsheetApp.getActiveSpreadsheet();
  
   var id = ss.getId();
  
   // setup sheets
   var yesterdaySheet = ss.getSheetByName('Yesterday');
   var last7DaysSheet = ss.getSheetByName('Last 7 Days');
   var last30DaysSheet = ss.getSheetByName('Last 30 Days');
   var settingsSheet = ss.getSheetByName('Settings');
   var dashboardURL = ss.getUrl() + &quot;?usp=sharing&quot;;
  
   // Send the PDF of the spreadsheet to this email address
   // get this from the settings sheet
   var email = settingsSheet.getRange(8,2).getValue();
   var cc_email = settingsSheet.getRange(9,2).getValue();
   var bcc_email = settingsSheet.getRange(10,2).getValue();
  
   // Subject of email message
   var subject = &quot;Dashboard PDF generated from &quot; + ss.getName() + &quot; - &quot; + new Date().toLocaleString(); 
  
   // Email Body
   var body = `A pdf copy of your dashboard is attached.&lt;br&gt;&lt;br&gt;
  
    To access this Google Sheet,; 
     &lt;a href=&quot;` + dashboardURL + `&quot; &gt;click here&lt;/a&gt;`;
  
  
   // Base URL
   var url = &quot;https://docs.google.com/spreadsheets/d/&quot; + id + &quot;/export?&quot;;
   var url_ext = 'exportFormat=pdf&amp;format=pdf&amp;size=A4&amp;portrait=false&amp;fitw=true&amp;gid=';
    
   // Auth value
   var token = ScriptApp.getOAuthToken();
  
   var options = { 
  
    headers: { 'Authorization': 'Bearer ' + token }
  
     }
  
   // helps initialize first time using the script
   var driveCall = DriveApp.getRootFolder();  
  
   // create the pdf
   var responseYesterday = UrlFetchApp.fetch(url + url_ext + yesterdaySheet.getSheetId(), options);
   var response7Days = UrlFetchApp.fetch(url + url_ext + last7DaysSheet.getSheetId(), options);
   var response30Days = UrlFetchApp.fetch(url + url_ext + last30DaysSheet.getSheetId(), options);
   
  
   // send the email with the PDF attachment
   GmailApp.sendEmail(email, subject, body, {
    cc: cc_email,
    bcc: bcc_email,
    htmlBody: body,
    attachments:[responseYesterday,response7Days, response30Days]   
   });
  }
  </code></pre>