Google Apps脚本-将Google表格作为电子邮件附件发送 [英] Google Apps Script - Send Google Sheet as Email Attachment

查看:69
本文介绍了Google Apps脚本-将Google表格作为电子邮件附件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用Google Apps脚本将Google工作表作为电子邮件附件发送.当我执行代码(如下所示)时,即使我没有指定我想以这种格式发送,它也会自动将其发送为PDF.

I am currently trying to send a google sheet as an email attachment using Google Apps Script. When I execute the code (shown below) it automatically sends it as a PDF even though I have not specified I want to send it in this format.

是否可以使用Google表格格式发送附件?

Is there a way to send the attachment in Google Sheet format?

{
    try
    {
      // Get file from Google Drive
      var googleSheet = DriveApp.getFileById("xxxxxxxxxxxxxxxx")

      // Send email with file attached
      MailApp.sendEmail("name@email.co.uk", "Report", "Please see the attached report.", {attachments: googleSheet})
    }
    catch (exception)
    {
        Logger.log(exception);
    }
}


推荐答案

  • 附件的文档指定:
    • The documentation for attachment specifies:
    • 这是一个常规的Blob

      This is a regular Blob

      • 有关 blob的contentType的文档说:
      • contentType

        contentType

        要转换为的MIME类型.对于大多数Blob,"application/pdf"是唯一有效的选项.

        The MIME type to convert to. For most blobs, 'application/pdf' is the only valid option.

        您可以做两件事

        • 如果您想将Google电子表格作为电子表格发送-您需要将链接发送到邮件正文中的文件,而不是将文件添加为附件
        • 如果您要以其他文件格式(例如xls)发送文件-您需要事先手动将其转换为这种格式-例如如此处
        • 这篇关于Google Apps脚本-将Google表格作为电子邮件附件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆