繁体   English   中英

在代码中找到现有的Google表格图表类型的最有效方法是什么(Google脚本)?

[英]What is the most effective way to find an already existing Google Sheets chart type in code (Google Scripts)?

对于我一生,我找不到Google提供的任何文档,也找不到在线答案,这些文档确实可以帮助我理解和回答有关如何使用getChartType()

我正在尝试使用Google脚本访问具有多个图表,饼图和条形图的特定Google Spreadsheet。 我要做的就是在Google脚本的代码中找出如何查找图表类型。 根据我的研究, getChartType()似乎是最好的选择,但是我发现的任何示例代码都会引发错误。

如果有更好或更简单的方法来查找EmbeddedChart是什么类型的图表,那么我完全愿意提出建议。 如果getChartType()是最佳选择,请帮助我了解如何专门使用它。

我已经尝试过这些来源,以及更多:

https://developers.google.com/apps-script/reference/spreadsheet/embedded-pie-chart-builder

https://developers.google.com/chart/interactive/docs/reference#chartwrapperobject

好的,在进一步搜索Google Apps脚本文档后,我将两个和两个放在一起,并得出了如何获取现有图表类型的方法。 您必须嵌套一些功能,这是我起初并未完全理解的功能。 要获取现有的图表类型,请输入以下代码:

var charts = SpreadsheetApp.openByUrl('sheeturl').getActiveSheet().getCharts();

var chart_types = [];
  for(i = 0; i < charts.length; i++)
    if(charts[i]){chart_types.push(charts[i].modify().getChartType());}

Logger.log(chart_types);

这返回了(以饼图和条形图为例): [PIE, BAR] 在这种情况下,对我来说,关键是将.modify().getChartType().getCharts()结合使用

暂无
暂无

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

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