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

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

问题描述

我有一张表格,其中的单元格具有函数/公式,如下所示:

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

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

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?

感谢您的帮助!

推荐答案

您可以像复制值一样轻松地复制公式,只需使用 Range.getFormula()Range.setFormula() 而不是 .getValue().setValue().请参阅电子表格服务文档.

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.

在最后一行下面插入一行是非常基本的,使用 insertRowAftergetLastRow在一个简单的脚本中.

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天全站免登陆