问题
Hi I am trying to get the data on my google sheet to be recalculate every minute
by using this script.
var sh = SpreadsheetApp.getActiveSheet();
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var r = "A1";
var f = '=ImportHTML("https://coinmarketcap.com/all/views/all/","table")';
sh.getRange(r).setFormula(f);
Utilities.sleep(2000);
sh.getRange(2,2,sh.getLastRow(),sh.getLastColumn()-1).setValues(sh.getRange(1,1,sh.getLastRow(),sh.getLastColumn()-1).getValues());
}
but I got a a #REF error in the sheet
I just want the data been recalculated
any help ?
回答1:
Answer:
You can do this by clearing the Sheet and re-loading the formula, on a time-based Installable trigger.
Code:
function getData() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var r = "A1";
var f = '=ImportHTML("https://coinmarketcap.com/all/views/all/","table")';
sheet.clear();
sheet.getRange(r).setFormula(f);
}
function getData2() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var r = "A1";
var f = '=ImportHTML("https://bitinfocharts.com/","table")';
sheet.clear();
sheet.getRange(r).setFormula(f);
}
I hope this is helpful to you!
References:
- Installable Triggers | Apps Script | Google Developers
来源:https://stackoverflow.com/questions/60798310/importhtml-recalculation-by-the-minute