Created
November 29, 2012 14:57
-
-
Save anonymous/4169590 to your computer and use it in GitHub Desktop.
Get Google Spreadsheet as PDF with customizations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function spreadsheetToPDF(key) { | |
var oauthConfig = UrlFetchApp.addOAuthService("spreadsheets"); | |
var scope = "https://spreadsheets.google.com/feeds" | |
oauthConfig.setConsumerKey("anonymous"); | |
oauthConfig.setConsumerSecret("anonymous"); | |
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope); | |
oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken"); | |
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); | |
var requestData = { | |
"oAuthServiceName": "spreadsheets", | |
"oAuthUseToken": "always", | |
}; | |
var name = DocsList.getFileById(key).getName()+".pdf"; | |
var pdf = UrlFetchApp.fetch("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+key+"&exportFormat=pdf&gid=1&gridlines=0&printtitle=0&size=7&fzr=true&portrait=1&fitw=1", requestData).getBlob().setName(name); | |
return pdf; | |
} |
Hi thanks, this looks like a really useful code. When I try to run this code, it requires some kind of authorization. What do I have to do for that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had been looking for a solution to this problem for a while. Thanks this worked for me.