gpt4 book ai didi

google-apps-script - 强制刷新 ImportXML

转载 作者:行者123 更新时间:2023-12-05 07:42:09 33 4
gpt4 key购买 nike

我想强制 importXML 每五分钟自动刷新一次。这是我尝试运行并收到错误“错误值(第 7 行,文件“RefreshImports”)的脚本。我不知道为什么。我在这里找到它:Periodically refresh IMPORTXML() spreadsheet function

function RefreshImports() {
var lock = LockService.getScriptLock();
if (!lock.tryLock(5000)) return; // Wait up to 5s for previous
refresh to end.

var id = "[YOUR SPREADSHEET ID]";
var ss = SpreadsheetApp.openById(id);
var sheet = ss.getSheetByName("[SHEET NAME]");
var dataRange = sheet.getDataRange();
var formulas = dataRange.getFormulas();
var content = "";
var now = new Date();
var time = now.getTime();
var re = /.*[^a-z0-9]import(?:xml|data|feed|html|range)\(.*/gi;
var re2 = /((\?|&)(update=[0-9]*))/gi;
var re3 = /(",)/gi;

for (var row = 0; row < formulas.length; row++) {
for (var col = 0; col < formulas[0].length; col++) {
content = formulas[row][col];
if (content != "") {
var match = content.search(re);
if (match !== -1) {
// import function is used in this cell
var updatedContent = content.toString().replace(re2, "$2update=" +
time);
if (updatedContent == content) {
// No querystring exists yet in url
updatedContent = content.toString().replace(re3, "?update=" + time +
"$1");
}
// Update url in formula with querystring param
sheet.getRange(row + 1, col + 1).setFormula(updatedContent);
}
}
}
}

// Done refresh; release the lock.
lock.releaseLock();

// Show last updated time on sheet somewhere
sheet.getRange(7, 2).setValue("Rates were last updated at " +
now.toLocaleTimeString())
}

在显示“[YOUR SPREADSHEET ID]”的代码中,我输入的电子表格名称是否正确?我对此一无所知。

最佳答案

[YOUR SPREADSHEET ID] 上,您应该添加电子表格 ID,而不是它的名称。

电子表格 ID

https://docs.google.com/spreadsheets/d/1Xhgfr3z4EwPtjS4aahytU_3TOVxjNb8JvHo88h3nZaE/edit#gid=14522064

1Xhgfr3z4EwPtjS4aahytU_3TOVxjNb8JvHo88h3nZaE

关于google-apps-script - 强制刷新 ImportXML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44740987/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com