【问题标题】:Generating Google doc from template, needing to link within email从模板生成谷歌文档,需要在电子邮件中链接
【发布时间】:2020-12-28 10:31:27
【问题描述】:

我在下面有部分 Google 脚本,我已将其设置为从带有从 Google 表单添加的变量的模板生成新文档。

然后将新文档转换为 PDF 并作为附件通过电子邮件发送。

我现在还想做的是包含一个指向 Google 文档本身的超链接。

我可以看到 DocumentApp.openByUrl 是一个可能的函数,但不知道如何应用它。

autoFillGoogleDocFromForm

  //e.values is an array of form values
  var Timestamp = e.values[0];
  var Channel = e.values[1];
  var Name = e.values[2];;
  
  var file = DriveApp.getFileById('FILEID'); 
  
  var folder = createChannelFolder(); // 1st modification point
  var copy = file.makeCopy(Channel + ',' + Name, folder); 
  var newId = copy.getId();
  var doc = DocumentApp.openById(newId); 

  var body = doc.getBody(); 
  body.replaceText('{{Timestamp}}', Timestamp); 
  body.replaceText('{{Channel}}', Channel);  
  body.replaceText('{{Name}}', Name);
         
  doc.saveAndClose(); 
}

发送 html 电子邮件

  //Setup embedded image.
  var imgID = "IMAGEID"
  var imageURL = "https://drive.google.com/uc?id="+imgID;
  var imageBlob = UrlFetchApp
                         .fetch(imageURL)
                         .getBlob()
                         .setName("imageblob");
  var body = HtmlService.createTemplateFromFile("html");
  body.Name = Name;
  body.Channel = Channel;
  var Blob = doc.getBlob().getAs('application/pdf');
  var Email = Email;
  var subject = 'Submitted'; 
  var values = e.values;
    GmailApp.sendEmail(Email, subject, body, {htmlBody: body.evaluate().getContent(),
      inlineImages:
      {
        imageblob: imageBlob},
      attachments: [{
      fileName: Channel + ".pdf",
      content: Blob.getBytes(),
      mimeType: "application/pdf"}]
});                                         
}

【问题讨论】:

    标签: google-apps-script google-docs google-forms google-docs-api


    【解决方案1】:

    你应该使用getUrl()

    我不知道这两个代码块是如何相关的,也不知道你想在哪里包含 URL,但上面链接中的示例应该很有帮助。类似的东西

    var doc = DocumentApp.openById(newId);
    var url = doc.getUrl();
    

    【讨论】:

    • 我可以获取 URL 并将其包含在 .html 文件中,然后使用函数 GmailApp.sendEmail 发送该文件,但似乎没有明显的超链接 URL 方法。
    • 我不确定你的意思@EwanFarry
    • 嗨,没问题了,我一定是添加了格式错误的超链接。我说服自己,我拥有的 = newFileUrl ?> 的 scriptlet 不是您可以链接到的东西,但它确实有效; 点击这里
    猜你喜欢
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多