问题
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