Export Google Sheets to PDF without cell gridlines

Adam Butenko Source

I'm trying to export PDF from Google Sheets via Apps Script. I've found useful code online, which works perfectly, except I can't find a way to export it without the grid, or change margins and page size.

function generatePdf() {
  var originalSpreadsheet = SpreadsheetApp.getActive();
  var sourcesheet = originalSpreadsheet.getSheetByName("TestSheet");
  var sourcerange = sourcesheet.getRange('B1:K55');  // range to get - here I get all of columns which i want
  var sourcevalues = sourcerange.getValues();
  var data = sourcesheet.getDataRange().getValues();

  var number =  originalSpreadsheet.getRange('G9:H9').getValue();

  var newSpreadsheet = SpreadsheetApp.create("Invoice pdf"); // can give any name.
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var projectname = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = sourcesheet.copyTo(newSpreadsheet);
  var destrange = sheet.getRange('B1:K55');
  destrange.setValues(sourcevalues);
  newSpreadsheet.getSheetByName('Sheet1').activate();
  newSpreadsheet.deleteActiveSheet();

  var invoiceName = "Invoice "+number;
  var pdf = DriveApp.getFileById(newSpreadsheet.getId());
  var theBlob =     pdf.getBlob().getAs('application/pdf').setName(invoiceName);

  var folderID = "1Y7n1e_tzQWvzVykHJf_DSm9lBVmokDHA"; // Folder id to save in a folder.
  var folder = DriveApp.getFolderById(folderID);
  var newFile = folder.createFile(theBlob);

  DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);  
}

I've been looking for answers everywhere, but I cannot apply some of the solutions I find to my code.

google-apps-scriptgoogle-spreadsheetexport-to-pdf

Answers

comments powered by Disqus