google docs链接的图表使用api或apps脚本刷新 [英] google docs linked charts refresh with api or apps script

查看:67
本文介绍了google docs链接的图表使用api或apps脚本刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google文档,该文档显示在我网站的iframe中以进行公开编辑,其中包含来自公开电子表格的链接图表,

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,

我使用电子表格api更改了图表数据,但是文档中的图表不会自动刷新,并且由于"更新按钮",我无法对文档中的图表进行全部更新或更新;被禁用

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,

所以我想使用google docs api或apps脚本刷新图表,我没有找到使用 google docs api 的方法,并且应用脚本不会在iframe中触发,

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.

推荐答案

很遗憾,无法以编程方式刷新Google文档中的图表.您绝对应该提交 SheetsChart 的功能请求 Google幻灯片应用脚本服务中的支持.

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.

由于更新功能目前可用于幻灯片,因此您可以实现将幻灯片设置为文档样式并将其在iFrame中使用的功能.按照此更新逻辑,例如,您将能够每分钟触发一次SheetsChart刷新:

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());
                 });
}

文档的解决方法

但是,由于您的目标是向网站查看者提供iFrame的最新版本,因此可以在文档保存"中自动完成:

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:

文件>在网络上发布>选中更改后自动重新发布

尽管如此,您将不得不手动更新文档中的图表.但是此更改将自动反映在您的网页中.

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

这篇关于google docs链接的图表使用api或apps脚本刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆