问题
I've searched all over for some lines of code that would accomplish what I want, but I'm too unfamiliar with how google apps script works. I've only ever coded in Microsoft excel and although I'm not completely lost, I'm still pretty lost.
I am looking for code that would select a range, then "Download as.." the selection to PDF, fit width, portrait, no grid. Ideally this PDF could be sent to a specific folder on my desktop, but I don't know if the apps script supports that.
I've found the methods needed (I think) to establish the width, portrait, no grid. All the other searches I've done convert the entire sheet to a PDF and email it which isn't what I want to do and I couldn't find what parts of those sample codes to delete because it looks like PDFs are recognized as web addresses. Any help would be greatly appreciated.
回答1:
It appears there is no direct way to convert a Range to a PDF (blob) in Google Apps Script. The best you could do is copy the range values to a blank spreadsheet, apply your formatting, then export that sheet.
You could write the PDF to a folder on Google Drive, then use the Drive software on your computer to sync that folder to the one on your desktop accomplish the last part.
I don't have a snippet of code that does this handy, but here are the relevant documentation links:
https://developers.google.com/apps-script/reference/spreadsheet/range#getvalues
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#create(String)
https://developers.google.com/apps-script/reference/spreadsheet/range#setValues(Object)
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getAs(String)
https://developers.google.com/apps-script/reference/drive/drive-app#createFile(String,String,String)
来源:https://stackoverflow.com/questions/32703960/export-a-range-as-a-pdf-in-google-apps-script