ImportHTML recalculation by the minute

房东的猫 提交于 2021-02-11 14:46:30

问题


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

enter image description here

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

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