Google 应用脚本:通过电子邮件将电子表格作为 excel [英] Google app scripts: email a spreadsheet as excel

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

问题描述

如何制作一个应用脚本,将电子表格作为 Excel 文件附加并通过电子邮件发送到某个电子邮件地址?

How do you make an app script which attaches a spreadsheet as an excel file and emails it to a certain email address?

在 Stackoverflow 上有一些关于如何执行此操作的较旧帖子,但是它们现在似乎已经过时并且似乎有效.

There are some older posts on Stackoverflow on how to do this however they seem to be outdated now and do not seem to work.

谢谢.

推荐答案

看起来@Christiaan Westerbeek 的回答是正确的,但距离他的帖子已经一年了,我认为需要对他在上面给出的脚本.

It looks like @Christiaan Westerbeek's answer is spot on but its been a year now since his post and I think there needs to be a bit of a modification in the script he has given above.

var url = file.exportLinks[MimeType.MICROSOFT_EXCEL];

这行代码有问题,可能是 exportLinks 现在已经贬值了.当我执行他的代码时,它给出了以下效果的错误:

There is something wrong with this line of code, maybe that exportLinks has now depreciated. When I executed his code it gave an error to the following effect:

TypeError:无法从未定义中读取属性application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".

TypeError: Cannot read property "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" from undefined.

解决方法如下:

上面这行代码中的URL基本上是download as xlsx"的URL,可以用来直接将电子表格下载为从File>获取的xlsx文件;下载为 >Microsoft Excel (.xlsx)

The URL in the above line of code is basically the "download as xlsx" URL that can be used to directly download the spreadsheet as an xlsx file that you get from File> Download as > Microsoft Excel (.xlsx)

格式如下:

https://docs.google.com/spreadsheets/d/<<<ID>>>/export?format=xlsx&id=<<<ID>>;>其中 <<>> 应替换为您的文件 ID.

https://docs.google.com/spreadsheets/d/<<<ID>>>/export?format=xlsx&id=<<<ID>>> where <<>> should be replaced by the ID of your file.

查看此处以轻松了解如何从 Google 表格的 URL 中提取 ID.

Check here to easily understand how to extract the ID from the URL of your google sheet.

这篇关于Google 应用脚本:通过电子邮件将电子表格作为 excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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