【问题标题】:Formatting PDF attachment in Google Apps Script (MailApp.sendEmail)在 Google Apps 脚本 (MailApp.sendEmail) 中格式化 PDF 附件
【发布时间】:2015-07-24 18:11:16
【问题描述】:

我设置了一个脚本,将 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 = "xxxxx@xxxxx.xxx";
  
 var subject = "Contact List - " + formattedDate;
  
 var body = "Attached is the current contact list for " + formattedDate + "." + "\n\nPlease email xxxxx@xxxxx.xxx with any corrections or updates.";
  
 MailApp.sendEmail(email, subject, body, {
     name: 'xxxxx',
     attachments: [file.getAs(MimeType.PDF)]
 });
}

【问题讨论】:

    标签: pdf google-apps-script


    【解决方案1】:

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

    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);
    

    阅读提供的链接了解更多详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      相关资源
      最近更新 更多