[英]Google Sheets/Apps Script Copy Formula to new row
still fairly new to this.对此仍然相当陌生。 I have been able to trigger the creation of a new row on a separate tab using a checkbox.
我已经能够使用复选框在单独的选项卡上触发新行的创建。 On this new tab, there is a column that has formulas in it.
在这个新选项卡上,有一列包含公式。 When the new row is created (above the first one), I want the formula in the new row.
创建新行时(在第一行之上),我想要新行中的公式。 Here is what I have so far:
这是我到目前为止所拥有的:
if(sheet.getSheetName() == CLIENTS) {
var checkCell = ss.getActiveCell();
var checked = checkCell.getValue();
var clientNameCell = checkCell.offset(0,-8).getValue();
var clientType = checkCell.offset(0,-7).getValue();
var sessionChargeCell = checkCell.offset(0, -6).getValue();
var groupChargeCell = checkCell.offset(0,-5).getValue();
var softwareFee = checkCell.offset(0,-4).getValue();
var billFee = checkCell.offset (0,-3).getValue();
var targetSheet = ss.getSheetByName("Client Billing Projections");
var lCol = targetSheet.getLastColumn();
if (checkCell.getColumn() == NEWCLIENTCHECK && checked == true) {
var target = targetSheet.getRange(2, 1, 1, lCol);
var formulas = target.getFormulas();
targetSheet.insertRowBefore(2);
var newRow = targetSheet.getRange(2,1,2,lCol);
newRow.setFormulas(formulas);
}
}
I guess where I'm stuck is after the line targetSheet.insertRowBefore(2);
我想我被卡住的地方是在
targetSheet.insertRowBefore(2);
. . I think it has something to do with my use of getFormulas and setFormulas, but I really can't wrap my head around it.
我认为这与我对 getFormulas 和 setFormulas 的使用有关,但我真的无法理解它。 There's no syntax error here.
这里没有语法错误。 As you can see, I've collected values from my first sheet (CLIENTS);
如您所见,我已经从我的第一张表 (CLIENTS) 中收集了值; I intend to copy it onto this other tab, but I have to get the formula copied up as well.
我打算将它复制到另一个选项卡上,但我也必须复制公式。 Any help would be appreciated.
任何帮助,将不胜感激。
Here is an example of the sheet There's a lot of working code in there already. 这是工作表的一个例子那里已经有很多工作代码了。 Most of what you'll be looking at here is likely between lines 222 - 238. Everything else works so far.
您将在这里看到的大部分内容可能在第 222 - 238 行之间。到目前为止,其他一切都有效。
Client Billing Projections
.Client Billing Projections
表中的第 2 行中插入一个新行。 If my understanding is correct, how about this modification?如果我的理解是正确的,这个修改怎么样?
var formulas = target.getFormulas()
from var target = targetSheet.getRange(2, 1, 1, lCol);
var formulas = target.getFormulas()
从var target = targetSheet.getRange(2, 1, 1, lCol);
. newRow.setFormulas(formulas)
with var newRow = targetSheet.getRange(2,1,2,lCol)
.newRow.setFormulas(formulas)
和var newRow = targetSheet.getRange(2,1,2,lCol)
。 In this case, formulas
has 2 dimensional array including 2 rows.formulas
具有包含 2 行的二维数组。
When your script is modified, please modify as follows.当您的脚本被修改时,请进行如下修改。
var newRow = targetSheet.getRange(2,1,2,lCol);
To:
var newRow = targetSheet.getRange(2,1,1,lCol);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.