Google Apps Script in Google Sheet - Convert formulas to static values - cell function to value

假装没事ソ 提交于 2021-02-08 04:44:23

问题


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.


回答1:


Use the copyValuesToRange() method:

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 Documentation - Link



来源:https://stackoverflow.com/questions/33963765/google-apps-script-in-google-sheet-convert-formulas-to-static-values-cell-fu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!