Google Script:从最后一行插入新行拷贝函数/公式的函数 [英] Google Script: function that insert new row copying functions/formulas from last row

查看:99
本文介绍了Google Script:从最后一行插入新行拷贝函数/公式的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单元格有函数/公式,就像这样:


我需要一个脚本来创建一个新行,并将最后使用的行的函数/公式复制到该行。
我发现这个脚本创建了一个新行但它不复制函数/公式。如何在Google Script中执行此格式化复制任务而无需手动选择和复制?

感谢您的帮助!

Range.getFormula()和 Range.setFormula()而不是 .getValue() .setValue()。有关电子表格服务的文档



在最后一行下方插入一行很基本,使用 insertRowAfter and getLastRow 在一个简单的脚本。






编辑:如果你没有找到它,这是另一个简单的方法的例子,

 函数duplicateLastRow(){
var ss = SpreadsheetApp.getActiveSheet();
ss.insertRowAfter(ss.getLastRow());
ss.getRange(ss.getLastRow(),1,1,ss.getLastColumn())。copyTo(ss.getRange(ss.getLastRow()+ 1,1));
}


I have a table which cells have functions/formulas, like this one:

I need a script that create a new row copying to it the functions/formulas of the last used row. I find this script which create a new row but it doesn't copy functions/formulas. How could I implement this formatting copy task in Google Script without having to manually select and copy?

Thanks for any help!

解决方案

You can copy formulas just as easily you copy values, just use Range.getFormula() and Range.setFormula() instead of .getValue() and .setValue(). See documentation on spreadsheet service.

Inserting a row below the last one is pretty basic, use insertRowAfter and getLastRow in a simple script.


EDIT : in case you don't find it, here is an example of another simple way to do it, copying everything in one step

function duplicateLastRow(){
  var ss = SpreadsheetApp.getActiveSheet();
  ss.insertRowAfter(ss.getLastRow());
  ss.getRange(ss.getLastRow(),1,1,ss.getLastColumn()).copyTo(ss.getRange(ss.getLastRow()+1,1));
}

这篇关于Google Script:从最后一行插入新行拷贝函数/公式的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆