Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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
Javascript 在脚本中运行公式或在js中编写等效公式_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 在脚本中运行公式或在js中编写等效公式

Javascript 在脚本中运行公式或在js中编写等效公式,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,基于电子表格中的一个单元格,我试图用数据填充其他单元格。这就是我想要的 A1 = date #1 (Only value entered manually in the spreadsheet) A2 = date #2 (based on A1) A3 = date #3 (based on A1) A4 = value #1 (based on A2) A5 = value #2 (based on A3) 在电子表格中,单元格A2的计算方式如下(如果A1不是工作日,则获取前一个工作日):

基于电子表格中的一个单元格,我试图用数据填充其他单元格。这就是我想要的

A1 = date #1 (Only value entered manually in the spreadsheet)
A2 = date #2 (based on A1)
A3 = date #3 (based on A1)
A4 = value #1 (based on A2)
A5 = value #2 (based on A3)
在电子表格中,单元格A2的计算方式如下(如果A1不是工作日,则获取前一个工作日):

在电子表格中,单元格A3的计算如下:(如果A1+1个月不是工作日,则获取前一个工作日):

A4基于A2的结果,如下所示:

A4 = getA4(A2); //The getA4-function is already written
A5基于A3的结果,如下所示:

A5 = getA5(A3); //The getA5-function is already written
一个解决办法是:

1. Read the A1 cell to the script
2. Write the two WORKDAY formulas to the spreadsheet from the script.
3. Read the values of A1 and the now generated A2 and A3 cells from the spreadsheet.
4. Send the values of A2 and A3 to the getA4 and getA5-methods
5. Then write the resulting values to the spreadsheet using setFormulas(newRangeWithAllOfTheValues);
我的问题:

由于我正在尽量减少对电子表格的读/写操作,因此我只希望在一次读/写操作中完成此操作。因此,我想:

A) …将两个WORKDAY函数转换为JS函数,以便我可以直接调用getA4和getA5,或者

B) …在脚本中运行两个WORKDAY函数(如果可能的话),这样我就可以在变量中得到结果,然后直接调用getA4和getA5


我也不知道该怎么做…

我最终选择了我提出的解决方案。这是一个额外的读/写操作,但执行时间仅额外1秒,因此没有问题。
A5 = getA5(A3); //The getA5-function is already written
1. Read the A1 cell to the script
2. Write the two WORKDAY formulas to the spreadsheet from the script.
3. Read the values of A1 and the now generated A2 and A3 cells from the spreadsheet.
4. Send the values of A2 and A3 to the getA4 and getA5-methods
5. Then write the resulting values to the spreadsheet using setFormulas(newRangeWithAllOfTheValues);