简体   繁体   English

从API获取数据的自定义函数未更新

[英]Custom function getting data from API not updating

I have a custom function that get data from an API and it works. 我有一个自定义函数,可以从API获取数据,并且可以正常工作。 The problem is that the data it gets changes within minutes, but the cell where I call the formula doesn't update. 问题在于它获取的数据在几分钟之内就发生了变化,但是我调用公式的单元格却没有更新。 If I recalculate it (pressing enter) it doesn't update either. 如果我重新计算(按Enter),它也不会更新。 I have to delete the formula from the cell and re-enter it to get the data updated. 我必须从单元格中删除该公式,然后重新输入该公式以更新数据。 I guess the code isn't running again as the google sheet sees that nothing in the workbook has changed. 我猜代码没有再运行,因为Google工作表发现工作簿中的任何内容都没有更改。

How can I make it to update each 5 minutes for example? 例如,如何使它每5分钟更新一次?

So let us assume that you have a function named getData() that returns the data. 因此,让我们假设您有一个名为getData()的函数来返回数据。

Instead of returning the data, you could make the function insert the data to a specific cell calling 您可以使函数将数据插入到特定的单元格中,而不是返回数据

SpreadsheetApp.GetActiveSpreadsheet.GetActiveSheet().GetRange(row, col).setValue(data);

Now you could create a trigger that calls the function every five minutes. 现在,您可以创建一个每五分钟调用一次函数的触发器 One example is doing it programmatically like so: 一个示例是通过编程方式进行的,如下所示:

function createTimeDrivenTriggers() {
 // Trigger every 5 minutes.
ScriptApp.newTrigger('getData')
 .timeBased()
 .everyMinutes(5)
 .create();

Remember to execute the triggerbuilder from the code editor. 记住要从代码编辑器执行triggerbuilder。

Hope this was clear enough and helped at all. 希望这是足够清楚的,对我们有帮助。 I'll proofread and test the exact formatting once I get to a computer. 进入计算机后,我将校对并测试确切的格式。

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

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