Google电子表格sheet.getCharts()仅在打开电子表格时有效?

时间:2013-04-28 21:02:39

标签: charts google-apps-script google-sheets

电子表格关闭时,我无法获取工作表的图表。我的目标是更新图表并将其作为电子邮件发送,并且在Google电子表格打开时我已轻松管理该图表。 但是当CLOSED时,图表的长度为“0”。

var ss = SpreadsheetApp.getActiveSpreadsheet();
var charts = ss.getSheetByName("Sheet").getCharts();

那么,使用这个命令有什么限制,或者我错过了什么?

1 个答案:

答案 0 :(得分:3)

getActiveSpreadsheet仅在有活动电子表格时才有效。 (即:当电子表格打开时。)

您应该通过Class SpreadsheetApp(具体为openopenByIdopenByUrl)中详述的一种公开方法打开电子表格,然后将其设置为有效。

例如:

var testSpreadsheet = SpreadsheetApp.openById("1234567890");
SpreadsheetApp.setActiveSpreadsheet(testSpreadsheet);
相关问题