Google表格IMPORTHTML [英] Google Sheets IMPORTHTML
问题描述
我已经完成以下脚本.我想使用IMPORTHTML在Google表格中获取一个表格,只有当数据更改时,一切都可以正常工作,然后Google表格中的表格才不会更改.我使用触发器来运行整个过程,以便每分钟更新一次.但是问题来了,如果我让整个事情像这样运行并且网站上的数据发生变化,那么现在问题来了,在Google表格中没有变化,原来的价值观被一遍又一遍地取而代之再来一次,而不是新的.如果我手动从单元格中删除IMPORTHTML,然后将其复制回,则它的工作方式很奇怪.但是不幸的是,它不适用于脚本和触发器,我在做什么错了?
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);
}
推荐答案
在设置值之前先清除单元格的内容,然后 flush()
清除它:
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);
}
参考文献:
这篇关于Google表格IMPORTHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!