Google表格中的Google Apps脚本-将公式转换为静态值-将单元格函数转换为值 [英] Google Apps Script in Google Sheet - Convert formulas to static values - cell function to value

查看:61
本文介绍了Google表格中的Google Apps脚本-将公式转换为静态值-将单元格函数转换为值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种Google Apps脚本方法可以将具有公式的单元格更改为具有静态值的单元格?

Is there a Google Apps Script method that will change a cell with a formula to one with a static value?

这样做的原因是为了避免由于工作表变大而重新计算大量单元格公式而导致工作表出现滞后.

The reason for this is to avoid lag in the Sheet from lots of cell formulas recalculating as the sheet becomes larger.

我想让工作表将旧公式替换为静态值,因为它们不会更改.

I want to make the sheet replace old formulas with static values since they won't be changing.

推荐答案

使用 copyValuesToRange()方法:

function copyFormulasToValues() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sourceSheet = ss.getSheetByName("Sheet1");
 var destinationSheet = ss.getSheetByName("Sheet2");

 //getRange(start row, start column, number of Rows, number of Columns)
 var range = sourceSheet.getRange(1,1,1,1); //Copy content of A1

 range
  .copyValuesToRange(destinationSheet, 1, 1, range.getNumRows(), range.getNumColumns());
};

Google文档-链接

这篇关于Google表格中的Google Apps脚本-将公式转换为静态值-将单元格函数转换为值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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