google docs linked charts refresh with api or apps script

寵の児 提交于 2021-01-29 18:23:37

问题


I have a google doc that I show inside an iframe in my website for public editing, it contains linked charts from a public spreadsheet,

I change the chart data with spreadsheet api, but the chart in the doc does not refresh automatically, and I can't clic update or update all in the doc because the "update button" is disabled,

SO I wanted to use google docs api or apps script to refresh charts, I did not find how to do it with google docs api, and apps script does not trigger inside the iframe,

Can you please give me any idea how to do this, Thank you.


回答1:


Unfortunately there is no way to refresh charts programatically in a Google Document. You should definitely submit a feature request for SheetsChart support as there is in Google Slide App Script Service.

Workaround with Slides

Since the update feature is currently available for Slides you could achieve to style a Slide as a document and use it in your iFrame. Following this update logic you will be able to trigger a SheetsChart refresh every minute for example:

function myFunction() {
  ScriptApp.newTrigger('updateCharts').timeBased().everyMinutes(1).create();
}

function updateCharts() {
  let slides = SlidesApp.getActivePresentation().getSlides();
  slides.forEach(slide => {
                 let charts = slide.getSheetsCharts();
                 charts.forEach(chart=> chart.refresh());
                 });
}

Workaround with Documents

However, since your goal is to provide your website viewers with the last version of the iFrame this can be done automatically on Document save:

File > Publish on the Web > check Automatically republish when changes are made

You will have to update manually the chart in your Document though. But this change will be reflected in your webpage automatically.



来源:https://stackoverflow.com/questions/62794107/google-docs-linked-charts-refresh-with-api-or-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!