Google Sheets IMPORTHTML

ⅰ亾dé卋堺 提交于 2021-01-28 05:48:32

问题


I have completed the following script. I want to get a table in my Google Sheet with IMPORTHTML, everything works fine, only if the data changes, then that doesn't change in the Google table. I run the whole thing with a trigger so that will be updated every minute. But here comes the problem, if I let the whole thing run like this and the data changes on the website, and here comes now the problem that doesn't change in the Google Sheet, the old values ​​are simply taken over and over again and not the new ones. If I delete IMPORTHTML from the cell manually and then copy it back in, it works strangely. But unfortunately it doesn't work with the script and the trigger, what am I doing wrong?

function getData() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Lager123");
    
  var importXpath_1 = '=IMPORTHTML("URLwithSIMPLEtable","table", 1)';
  
  sheet.getRange("A1").setValue(importXpath_1);
  
}

回答1:


Clear the content of the cell and then flush() it before you set the value:

function getData() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Lager123");
    
  var importXpath_1 = '=IMPORTHTML("URLwithSIMPLEtable","table", 1)';
  sheet.getRange("A1").clearContent();
  SpreadsheetApp.flush();
  sheet.getRange("A1").setValue(importXpath_1);
  
}

References:

  • clearContent()

  • flush()



来源:https://stackoverflow.com/questions/63556446/google-sheets-importhtml

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