这只是我在这里的第三篇文章。我从未编码,我没有技能,我只是想学习一些概念,以便我可以“修复”Google Apps 脚本。
问题:我想了解setFormula和setValue行为,为什么细胞值更新与否。
我正在使用UrlFetchApp.fetch从 URL 获取一些值并在单元格中设置该值。
我正在用setFormulaor写入值setValue。
这些功能是从工作表中的菜单手动触发的(未在下面的脚本中编码)
所以我从“Url”获取数据并将它们写在单元格上。
函数的第一次运行:
如果 URL 中的数据为:“A”,则:
-->setFormula写“A” -->setValue写“A”
函数的第二次运行:
URL中的数据从“A”变为“B”,则:
-->setFormula不覆盖单元格,仍然是“A” -->setValue用“B”覆盖“A”
我知道脚本正在按预期运行,完全没有问题。我只是想了解为什么setFormula从上次运行中“知道”单元格已经写入,因此它不会更新值。
这是解释问题的简短脚本。Url 值设置在工作表上, https://engaliao.com/html.htm 正如您在此图片中看到的那样
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [
{name: "Formula", functionName: "runFormula"},
{name: "SetValue", functionName: "runSet"}
];
sheet.addMenu("Menu", entries);
}
function runFormula() {
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(
'hoja'
);
activeSheet.getRange(2, …Run Code Online (Sandbox Code Playgroud)