Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 使用应用程序脚本插入时未更新单元格公式_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 使用应用程序脚本插入时未更新单元格公式

Google apps script 使用应用程序脚本插入时未更新单元格公式,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我使用Apps脚本在单元格中插入了一个公式,在这个公式中有对同一行其他单元格的引用 问题是,我的应用程序脚本也会插入新行。并且公式保持不变。由于行索引已更改,引用应更改 我该怎么做 /* This function is called several times and so "A2" only makes sense at the time I set the formula, after that, it should become "A3" or "A4" */ function writ

我使用Apps脚本在单元格中插入了一个公式,在这个公式中有对同一行其他单元格的引用

问题是,我的应用程序脚本也会插入新行。并且公式保持不变。由于行索引已更改,引用应更改

我该怎么做

/* This function is called several times and so "A2" only makes sense
at the time I set the formula, after that, it should become "A3" or "A4"
*/
function writeDataLine(dataSheet, date, playerName, idx) {
  var formula = "=IF(VLOOKUP(A2;G$2:H;2;FALSE)=C2;1;0)"
  dataSheet.getRange(idx + 2, 4, 1, 1).setFormula(formula);
}
我写在D2中,并引用A2和C2

[编辑] 我尝试了R1C1表示法,但出现了错误


问题是您在设置公式R1C1时混合使用了RC和A1符号。如果没有方括号,RC是绝对值。因此,R2C7:R1000C8可用于G2:H1000

不管怎样,我认为你不需要剧本。我相信你想要的是

D2:

=ARRAYFORMULA(IF(VLOOKUP(A2:A100;G$2:H;2;FALSE)=C2:C100;1;0))

或者,您可以在范围D2上使用方法,而不使用R1C1

使用R1C1参考风险值公式==IFVLOOKUPR[0]C[-3];G2:H;2.假=R[0]C[-1];1.0和setFormulaR1C1,但我得到错误!什么错误!?分析错误G:H不是RCI与阵列公式一致。一开始我不想要,因为我没有第一行,第一行是由我的AppsScript填充的。但我终于有了要迁移的旧数据,所以我可以手工计算出我的公式
=ARRAYFORMULA(IF(VLOOKUP(A2:A100;G$2:H;2;FALSE)=C2:C100;1;0))