I am exporting a Google Spreadsheet to PDF format with Google Apps Script, and would like to 'include sheet names' on the PDF pages. Is this possible to do this from the code?
var spreadsheetFile = DocsList.getFileById(spreadsheet_id);
var blob = spreadsheetFile.getAs('application/pdf');
blob.setName(spreadsheetFile.getName());
DocsList.getFolder(file_destination).createFile(blob);
In the Spreadsheet app it is supported in the UI, so I am wondering whether Apps Scripts supports this too?
The
.getAs()
method does not allow for parameters but you can use the spreadsheet api where you can choose all the parameters available from the "normal" Ui. See this post answer to see how to use it, and follow the github linkHere is the demo code as there were a few inconsistencies in the code in ref. (just to illustrate with an example exporting sheet1 with grid and title)
note this will ask for 2 distinct authorizations.