繁体   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

每当我研究如何 email 图表时,所有答案都涉及使用 getAs function 将图表另存为图像,然后将其内联或附加到 Z0C83F57C7831A0B4AZA39EFABC23 但我正在努力将图表保存为图像以附加它。 当我运行以下代码时:

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

我收到此错误:

TypeError: demandLastWeekSheet.getCharts(...).getAs 不是 function (第 8 行,文件“代码”)

事实上,如果我从这里尝试.getBlob()、.modify() 或任何其他函数,我会得到同样的错误: https://developers.google.com/apps-script/reference/spreadsheet/embedded-chart.html

这些功能肯定没有被弃用吗? 我做错了什么/愚蠢吗? 应用程序脚本世界的新手,欢迎任何指针,如果这是一个措辞不当的问题,也很抱歉:我也是堆栈溢出的新手 :)

有什么建议么??

getCharts()返回EmbeddedChart[] 在您的脚本中, getAs方法用于数组。 我认为这是您的问题的原因。 为了使用getAs的方法检索图表的 blob,请进行如下修改。

从:

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

至:

var chart = demandLastWeekSheet.getCharts()[0].getAs("image/png");
  • 在此修改中,检索demandLastWeekSheet表中的第一个图表。 如果要检索第二张图表,请从[0]修改为[1]

参考:

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM