将电子表格导出为pdf,然后将文件保存在谷歌驱动器中 [英] exporting spreadsheet to pdf then saving the file in google drive
问题描述
在将Google电子表格打印为PDF后,我在保存到谷歌驱动器时遇到问题。
如果我只是把printurl字符串放到浏览器中,它会自动给我这个文件。但我希望它被自动保存到谷歌驱动器。我已经通过借用其他帖子的代码来试用此代码,这些帖子将电子表格作为PDF发送给电子表格。但是这会产生无法打开的pdf。我究竟做错了什么?
函数printpdf(){
var spreadsheet_id =0Aiy1DTQRndx6dDRidXoxNzlXZFhxd2FITTlBbnUybnc;
var settings ='& fitw = true& portrait = false& exportFormat = pdf& gid = 0& gridlines = false';
var printurl ='https://spreadsheets.google.com/feeds/download/spreadsheets/Export? key ='+ spreadsheet_id +设置;
var result = UrlFetchApp.fetch(printurl);
var content = result.getContent();
var file = DocsList.createFile(temp,content,application / pdf);
}
这是在新的oauth2格式下对这个问题的更新。
您可以使用更简单的方法时尚
函数printpdf(){
var spreadsheet_id =0Aiy1DTQRndx6dDRidXoxNzlXZFhxd2FITTlBbnUybnc;
var spreadsheetFile = DocsList.getFileById(spreadsheet_id);
var blob = spreadsheetFile.getAs('application / pdf');
DocsList.createFile(blob);请注意,DocsList.createFile(blob)仅适用于Google Apps帐户。请注意,DocsList.createFile(blob)仅适用于Google Apps帐户。
I'm having problems saving to google drive after printing a google spreadsheet to pdf.
If i just put the "printurl" string into a browser, it will automatically give me the file. But I want it to be saved to google drive automatically. I've tried this code by borrowing code from other posts that emails a spreadsheet as PDF. But this produces a pdf that is unable to be opened. What am I doing wrong?
function printpdf() {
var spreadsheet_id="0Aiy1DTQRndx6dDRidXoxNzlXZFhxd2FITTlBbnUybnc";
var settings = '&fitw=true&portrait=false&exportFormat=pdf&gid=0&gridlines=false';
var printurl = 'https://spreadsheets.google.com/feeds/download/spreadsheets/Export? key=' + spreadsheet_id + settings;
var result=UrlFetchApp.fetch(printurl);
var content=result.getContent();
var file=DocsList.createFile("temp",content,"application/pdf");
}
Here is an update to this question under the new oauth2 format.
Printing spreadsheet to PDF then saving file in Drive using OAuth2
解决方案 You can do it in a much simpler fashion
function printpdf(){
var spreadsheet_id="0Aiy1DTQRndx6dDRidXoxNzlXZFhxd2FITTlBbnUybnc";
var spreadsheetFile = DocsList.getFileById(spreadsheet_id);
var blob = spreadsheetFile.getAs('application/pdf');
DocsList.createFile(blob);
}
Note that the DocsList.createFile(blob) works only with Google Apps accounts.
这篇关于将电子表格导出为pdf,然后将文件保存在谷歌驱动器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!