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 将setFormula方法与appendRow一起使用_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 将setFormula方法与appendRow一起使用

Google apps script 将setFormula方法与appendRow一起使用,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我有一个GoogleApps脚本web应用程序,它从请求中获取值,并使用appendRow方法将它们插入新行。在插入值的旁边,我还想在几列中插入公式。是否可以在appendRow()中执行此操作?或者有没有其他方法可以获取刚刚添加的行的行号,通过getRange获取单元格,然后使用setFormula方法 请注意,我需要继续使用appendRow方法,而不是通过getLastRow解决问题,因为可以同时发出多个请求。如果需要最后一行,则必须使用getLastRow(),除非您希望自己跟踪它 您可

我有一个GoogleApps脚本web应用程序,它从请求中获取值,并使用appendRow方法将它们插入新行。在插入值的旁边,我还想在几列中插入公式。是否可以在appendRow()中执行此操作?或者有没有其他方法可以获取刚刚添加的行的行号,通过getRange获取单元格,然后使用setFormula方法


请注意,我需要继续使用appendRow方法,而不是通过getLastRow解决问题,因为可以同时发出多个请求。

如果需要最后一行,则必须使用getLastRow(),除非您希望自己跟踪它

您可以这样做:

function testtest() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const lr=sh.getLastRow()+1;
  const s=`=SUM(A${lr}:C${lr})`;
  sh.appendRow([1,1,1,s]);//use whatever values you wish
}

注意:您必须使用V8

如果需要最后一行,您必须使用getLastRow(),除非您想自己跟踪它

您可以这样做:

function testtest() {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  const lr=sh.getLastRow()+1;
  const s=`=SUM(A${lr}:C${lr})`;
  sh.appendRow([1,1,1,s]);//use whatever values you wish
}
注意:必须使用以“=”开头的V8

值才能被解释为公式: 要通过设置公式,只需提供公式本身,
'='
开始。它将被解释为一个公式。这与以下行为相同:

设置范围的值。该值可以是数字、字符串、布尔值或日期如果以“=”开头,则解释为公式

例子: 以“=”开头的值将被解释为公式: 要通过设置公式,只需提供公式本身,
'='
开始。它将被解释为一个公式。这与以下行为相同:

设置范围的值。该值可以是数字、字符串、布尔值或日期如果以“=”开头,则解释为公式

例子: