在Google Apps脚本中格式化PDF附件(MailApp.sendEmail)

问题描述 投票:0回答:1

我设置了一个脚本,将Google表格中的办公室联系人列表转换为PDF,并每月将其作为附件通过电子邮件发送到列表中。我正在试图弄清楚如何将PDF格式化为横向并删除网格线并且没有成功。我对脚本比较陌生,所以我肯定我错过了什么。这是我的代码。我很感激任何建议。谢谢!

function EmailSpreadsheetAsPDF() {
  
 var file = DriveApp.getFileById('xxxxx_spreadsheet_key_xxxxx');
  
 var formattedDate = Utilities.formatDate(new Date(), "GMT-7", "MMMM yyyy");
  Logger.log(formattedDate);
  
 var email = "[email protected]";
  
 var subject = "Contact List - " + formattedDate;
  
 var body = "Attached is the current contact list for " + formattedDate + "." + "\n\nPlease email [email protected] with any corrections or updates.";
  
 MailApp.sendEmail(email, subject, body, {
     name: 'xxxxx',
     attachments: [file.getAs(MimeType.PDF)]
 });
}
pdf google-apps-script
1个回答
0
投票

对的,这是可能的。但是,您必须为此目的使用UrlFetchApp。如图所示here(阅读文章#89),您可以使用以下命令将网格线可见性设置为false,同时将文件导出为PDF:

var pdfBlob = UrlFetchApp.fetch("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="
               +docKey
               +"&exportFormat=pdf&gid="
               +printSheetIndex
               +"&gridlines=false&printtitle=false&size=A4&sheetnames=false&fzr=true&portrait="
               +portraitInd
               +"&fitw=true"
               , requestData).getBlob().setName(docName);

阅读提供的链接以获取更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.