In the spreadsheet app itself, you have the options to print only a specific sheet. You also can turn off the grid lines when creating the pdf from within the app. Is there any way to do this via script when creating the pdf?
Take a look at this code snippet: https://gist.github.com/4169590
What it does is uses Google Spreadsheet built-in download as PDF functionality so the same sort of customization is possible, including hiding gridlines and specifying a worksheet. Play with GET parameters to get the desirable output. In the end, script converts PDF file to a blob which you can manipulate further in your own script. To get this running though you'll need an additional authorization for Spreadsheet feeds scope.
Hope it helps.
@rcknr, worked for me, more options below. (From: http://productforums.google.com/forum/#!msg/apps-script/wQvCF6yY1Qk/R0uyVmf-Xx0J )
other settings
fmcmd=12
size=legal/A4
fzr=true/false
portrait=false/true
fitw=true/false
gid=0/1/2
gridlines=false/true
printtitle=false/true
sheetnames=false/true
pagenum=UNDEFINED
attachment=false/true
true/false where sometimes required, I could not use 0/1 instead.
Google apps script to create a pdf of a specific sheet of a spreadsheet.
function generatePdf() {
var originalSpreadsheet = SpreadsheetApp.getActive();
var sourcesheet = originalSpreadsheet.getSheetByName("Sheet - Name");
var sourcerange = sourcesheet.getRange('A1:G7'); // range to get - here I get all of columns which i want
var sourcevalues = sourcerange.getValues();
var data = sourcesheet.getDataRange().getValues();
var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export"); // can give any name.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var projectname = SpreadsheetApp.getActiveSpreadsheet();
var sheet = sourcesheet.copyTo(newSpreadsheet);
var destrange = sheet.getRange('A1:G7');
destrange.setValues(sourcevalues);
newSpreadsheet.getSheetByName('Sheet1').activate();
newSpreadsheet.deleteActiveSheet();
var pdf = DriveApp.getFileById(newSpreadsheet.getId());
var theBlob = pdf.getBlob().getAs('application/pdf').setName("name");
var folderID = "Folder Id"; // Folder id to save in a folder.
var folder = DriveApp.getFolderById(folderID);
var newFile = folder.createFile(theBlob);
DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);
}
Unfortunately this currently isn't possible with Apps Script, but you can file a feature request on our issue tracker.
When you choose export to pdf, you get a messagebox with options. In the right side of this messagebox there are five checkboxes. Check the second one, then you will hide the gridlines in the export. I don't know the label of this checkbox, because I use another language than english.
Good luck!
- Robert
this is a solution
var blob = DriveApp.getFileById(idsheet).getAs("application/pdf");
blob.setName("name".pdf");
var dossier = DriveApp.getFolderById("0Bx71KaTqXxQPQUYyVEVyYkJ0bEU");
dossier.createFile(blob);
I simply hide the sheets that I don't want put in the pdf
© 2022 - 2024 — McMap. All rights reserved.