问题
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