Google-Sheets App Script to generate a custom email from inside Google Sheets

Just in case, in addition to the strategic solution of Alexander Ermolin. As far as I know you can’t print your documents in PDF via some printer. But you can make a PDF from spreadsheet pretty easy. Here is an example:

function myFunction() {

  var ID   = '';                                          // ID of your spreadsheet
  var copy = DriveApp.getFileById(ID).makeCopy();         // make a copy of the spreadsheet
  var ss   = SpreadsheetApp.openById(copy.getId())        // open the copy

  // convert all formulas into static values
  var range = ss.getActiveSheet().getDataRange();  // get data range
  var values = range.getDisplayValues();           // get all displayed values in the range
  range.setValues(values);                         // paste the values back
  
  while (ss.getSheets().length>1) ss.deleteSheet(ss.getSheets()[1]); // remove all sheets except the first one
  
  DriveApp.createFile(ss.getBlob().setName('sheet.pdf')); // make a PDF file
  copy.setTrashed(true);                                  // delete the copy

}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top