简体   繁体   English

我正在尝试从我的电子表格中获取图表以使用谷歌脚本发送 email,但 getAs() function 不起作用

[英]I'm trying to get a chart from my spreadsheet to send in an email using google script, but the getAs() function isn't working

Whenever I've looked into how to email a chart, all the answers involve some variation on using the getAs function to save the chart as an image and then either inlining it or attaching it to the email.每当我研究如何 email 图表时,所有答案都涉及使用 getAs function 将图表另存为图像,然后将其内联或附加到 Z0C83F57C7831A0B4AZA39EFABC23 But I'm struggling to save the chart as an image in order to attach it.但我正在努力将图表保存为图像以附加它。 When I run the following code:当我运行以下代码时:

var chart = demandLastWeekSheet.getCharts().getAs("image/png");

I get this error:我收到此错误:

TypeError: demandLastWeekSheet.getCharts(...).getAs is not a function (line 8, file "Code") TypeError: demandLastWeekSheet.getCharts(...).getAs 不是 function (第 8 行,文件“代码”)

In fact, I get the same error if I try.getBlob(), .modify() or any other functions from here: https://developers.google.com/apps-script/reference/spreadsheet/embedded-chart.html事实上,如果我从这里尝试.getBlob()、.modify() 或任何其他函数,我会得到同样的错误: https://developers.google.com/apps-script/reference/spreadsheet/embedded-chart.html

Surely these functions have not been deprecated?这些功能肯定没有被弃用吗? Am I doing something wrong/stupid?我做错了什么/愚蠢吗? New to the world of apps script, any pointers welcome, Sorry also if this is a badly phrased question: also I am new to stack overflow :)应用程序脚本世界的新手,欢迎任何指针,如果这是一个措辞不当的问题,也很抱歉:我也是堆栈溢出的新手 :)

Any suggestions??有什么建议么??

getCharts() returns EmbeddedChart[] . getCharts()返回EmbeddedChart[] In your script, the method of getAs is used for an array.在您的脚本中, getAs方法用于数组。 I think that this is the reason of your issue.我认为这是您的问题的原因。 In order to retrieve the blob of the chart using the method of getAs , please modify as follows.为了使用getAs的方法检索图表的 blob,请进行如下修改。

From:从:

var chart = demandLastWeekSheet.getCharts().getAs("image/png");

To:至:

var chart = demandLastWeekSheet.getCharts()[0].getAs("image/png");
  • In this modification, the 1st chart in the sheet of demandLastWeekSheet is retrieved.在此修改中,检索demandLastWeekSheet表中的第一个图表。 If you want to retrieve the 2nd chart, please modify from [0] to [1] .如果要检索第二张图表,请从[0]修改为[1]

Reference:参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试从谷歌电子表格发送 email,但是该消息并未复制超链接 - I'm trying to send an email from google spreadsheet, however the message is not copying the hyperlink 我正在尝试使用Google Maps Javascript API添加标记,但它无法正常工作 - I'm trying to add a marker using Google Maps Javascript API but it isn't working Google Apps Script 通过电子表格发送电子邮件不起作用 - Google Apps Script send email through spreadsheet not working 谷歌脚本发送电子邮件功能不起作用 - Google Script Send email function Not working Google Apps 脚本:尝试使用.getAs(MimeType.PLAIN_TEXT) 从 Google Drive 读取文本文件 - Google Apps Script: trying to read a text file from Google Drive with .getAs(MimeType.PLAIN_TEXT) 所以我正在尝试使用 Math.cbrt 并且我的代码没有按预期工作 - So I'm trying to use Math.cbrt and my code isn't working as expected 我正在尝试将数字提高到其连续的功效,而我的代码不起作用 - I'm trying to raise numbers to their consecutive powers and my code isn't working 我正在尝试使用node和ajax上传文件,但是ajax调用不起作用? - I'm trying to upload a file using node and ajax but the ajax call isn't working? 我正在尝试在 email 中将谷歌表格中的范围作为 pdf 发送。 我的脚本卡在 getid() - I am trying to send a range in google sheets as a pdf in an email. My script is getting stuck on getid() 尝试让更多负载按钮在Instagram Instafeed脚本上运行,但在我的网站中没有响应 - Trying to get a load more button working on an Instagram Instafeed script but it isn't responding in my site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM