Refresh live Google Finance data prior to reading value

寵の児 提交于 2019-12-13 03:59:31

问题


I am trying to copy content from one column to another. Source column has formula based content like =GOOGLEFINANCE(SYMBOL,"PRICE") which gets updated every minute.

I have created trigger which runs for every 5min. But while copying it doesn't copy latest value which is seen in sheet, instead it copies initial value from formula. Lets say initial stock value is 100, later it changes to 105. When the function runs, my script copies 100 to the destination range.

...
var ss = SpreadsheetApp.getActive().getSheetByName("Sheet1");
ss.getRange(startRowRange).copyTo(ss.getRange(col), {contentsOnly:true});

How can I read the current, displayed value of =GOOGLEFINANCE() cells?


回答1:


As @tehhowch suggested, flush did the trick. Calling this applies all pending Spreadsheet changes at that point of time.

var ss = SpreadsheetApp.getActive().getSheetByName("Sheet1");
SpreadsheetApp.flush();
ss.getRange(startRowRange).copyTo(ss.getRange(col), {contentsOnly:true});

Read more about flush() here



来源:https://stackoverflow.com/questions/52747520/refresh-live-google-finance-data-prior-to-reading-value

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