Google应用脚本:以excel的形式发送电子表格 [英] Google app scripts: email a spreadsheet as excel

查看:137
本文介绍了Google应用脚本:以excel的形式发送电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何制作应用程序脚本,将电子表格作为excel文件附加到电子邮件并将其发送到某个电子邮件地址?

Stackoverflow上有一些旧帖子如何做到这一点,但他们现在似乎已经过时,而且 似乎无法正常工作。



谢谢。

解决方案

看起来像@Christiaan Westerbeek的答案是现货,但自从他发布以来,它已经有一年了,我认为需要在上面给出的脚本中做了一些修改。

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

这行代码有问题,也许 exportLinks 已经折旧。当我执行他的代码时,它给出了以下错误:


TypeError:无法读取属性 application / vnd.openxmlformats-officedocument.spreadsheetml.sheet 来自undefined。


解决方法如下:

上述行中的网址的代码基本上是可下载为xlsx的URL,可用于直接将电子表格下载为您从 File>获取的xlsx文件。下载为> Microsoft Excel(.xlsx)



格式为:


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


检查此处轻松了解如何从Google表格的网址中提取ID。


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

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.

Thank you.

解决方案

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

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: Cannot read property "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" from undefined.

The workaround is as follows:

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)

This is the format:

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

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

这篇关于Google应用脚本:以excel的形式发送电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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