[英]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,请进行如下修改。
var chart = demandLastWeekSheet.getCharts().getAs("image/png");
var chart = demandLastWeekSheet.getCharts()[0].getAs("image/png");
demandLastWeekSheet
is retrieved.demandLastWeekSheet
表中的第一个图表。 If you want to retrieve the 2nd chart, please modify from [0]
to [1]
.[0]
修改为[1]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.