我已经将代码重写为match the other answers for similar issues,但是它不能解决脚本问题。它发送带有pdf附件的电子邮件,但没有收到任何错误,但是我无法打开文件。我已经尝试了在stackoverflow上发布的多种解决方案。
什么是导致pdf在发送后损坏的原因?我已经重组了网址,但没有运气。
function emailPDF() {
SpreadsheetApp.flush();
var ss = SpreadsheetApp.openByUrl('url')
var sheet = ss.getSheetByName('Reviews Due');
var row = 2;
var col = 2;
var test = sheet.getRange(row,col).getValue();
if (test == "New Employee Reviews"){
var token = ScriptApp.getOAuthToken();
var params = {
headers: {
'Authorization': 'Bearer ' + token,
},
'muteHttpExceptions' : true
};
var sheetId = sheet.getSheetId();
var url_base = "https://docs.google.com/spreadsheets/d/" + ss.getId() + "/" + "export?";
var url_ext = 'exportFormat=pdf'
+ '&format=pdf'
+ '&gid=' + sheetId
+ '&size=letter'
+ '&portrait=false'
+ '&fitw=true'
+ '&sheetnames=false'
+ '&printtitle=false'
+ '&pagenumbers=false'
+ '&gridlines=false'
+ 'fzr=false';
var response = UrlFetchApp.fetch(url_base + url_ext, params);
var blob = response.getBlob().setName("Reviews Due" + ".pdf");
以下是电子表格的网址: https://docs.google.com/spreadsheets/d/1wmnw9Nl6B0e8IgVDgTEtGLzWhh1ssSgCLiOMsgs6Z64/edit#gid=1633156004
这是我将工作表导出为pdf时的网址: 文件:/// C:/Users/gwaldo/Downloads/Master%20Progression%20Schedule%20-%20Reviews%20Due.pdf
当我更改blob变量以包含getAs()时,这是它导出的pdf:non corrupted pdf, but no data
Logger.log(url_base + url_ext)= https://docs.google.com/spreadsheets/d/1wmnw9Nl6B0e8IgVDgTEtGLzWhh1ssSgCLiOMsgs6Z64/export?Format=pdf&format=pdf&gid=1633156004&size=letter&portrait=false&fitw=true&sheetnames=false&printtitle=false&pagenumbers=false&gridlines=falsefzr=false
%PDF-1.4%����40obj<</Type/Catalog/Names<<
/JavaScript30R>>/PageLabels<</Nums[0<</S/D/St1>>]>>
/Outlines20R/Pages10R>>endobj50obj<</Creator(��
<!DOCTYPE html><html lang="en"><head><meta name="description" content="Web
word processing, presentations and spreadsheets"><meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-
scale=1.0, user-scalable=0"><link rel="shortcut icon"
href="//ssl.gstatic.com/docs/common/drive_favicon1.ico"><title>Page Not
Found</title><meta name="referrer" content="origin"><link
href="//fonts.googleapis.com/css?family=Product+Sans" rel="stylesheet"
type="text/css"><style nonce="L3gm1PN3u9lyxQbOyJWDIQ">
答案 0 :(得分:0)
根据RFC2616
的400状态代码是
10.4.1 400错误的请求
由于语法格式错误,服务器无法理解该请求。
似乎查询参数的语法之一不被理解或格式不正确。仅添加var url_ext='format=pdf'
有助于隔离问题。通过OP测试了每个参数后,似乎fzr=false
引起了问题,因为之前缺少&