【发布时间】:2015-09-09 10:49:06
【问题描述】:
我正在发送带有 Google 电子表格和 Google 脚本的自动报告。
到目前为止,它运行良好。但不知何故,当我尝试创建要通过电子邮件发送的新报告时,函数“UrlFetchApp.fetch”返回 404。当我尝试复制旧报告时发生了同样的情况。
带有“UrlFetchApp.fetch”的行给了我这个错误:
https://docs.google.com/spreadsheets/d/1qm_bCKn4MbLKy7AIuIeu7bTZcTk8ObYBln0GAxwfsX8/pub?gid=195635557&single=true&output=pdf 的请求失败,返回代码 404。服务器响应被截断
看来我不是唯一遇到问题的人,但我找不到任何解决方案。
代码如下:
function emailSpreadsheetAsCSV() {
var ss = SpreadsheetApp.openById("1qm_bCKn4MbLKy7AIuIeu7bTZcTk8ObYBln0GAxwfsX8");
var url = ss.getUrl();
url = url.replace(/edit$/,'');
var token = ScriptApp.getOAuthToken();
var sheets = ss.getSheets();
//make an empty array to hold your fetched blobs
var blobs = [];
for (var i=0; i<sheets.length; i++) {
var response = UrlFetchApp.fetch("https://docs.google.com/spreadsheets/d/1qm_bCKn4MbLKy7AIuIeu7bTZcTk8ObYBln0GAxwfsX8/pub?gid=195635557&single=true&output=pdf", {
headers: {
'Authorization': 'Bearer ' + token
},
'muteHttpExceptions': false
});
//convert the response to a blob and store in our array
blobs[i] = response.getBlob().setName(sheets[i].getName() + '.csv');
}
//create new blob that is a zip file containing our blob array
var zipBlob = Utilities.zip(blobs).setName(ss.getName() + '.zip');
return blobs[0];
}
非常感谢您的帮助。
艾美式。
【问题讨论】:
-
对不起。希望现在更清楚了。
-
指定多个调用中的哪一个失败。只发布需要的代码。
-
现在怎么样?是不是更清楚了?
-
查看官方文档如何正确地将文档转换为 pdf。它是一种方法。
标签: google-apps-script google-docs