Не существует регулярного выражения для поиска формулы определенного типа в листе с точки зрения макроса. Вместо этого, если вы хотите сохранить конкретные формулы, но не другие, вам нужно будет проверить каждую ячейку с помощью формулы и определить, хотите ли вы ее сериализовать против той, которую хотите сохранить. Затем, если это тот, который вы хотите сериализовать, прочитайте значения из исходного листа и запишите их в копию:
function copyFormulasAndSomeValues() {
var source = SpreadsheetApp.getActive(). getActiveSheet();
var remote = SpreadsheetApp.openById("some ID");
// Copy all static values and formulas (and charts, formatting, etc.)
var dest = source.copyTo(remote);
// To efficiently read and write values when we know nothing
// about the structure of invalid formulas, we will use a RangeList.
// If structure exists (e.g. if a1 is invalid we know `A2:A100` will be too), we can combine batch
// get/set methods with the 4 parameter getRange() method.
var toRead = [];
// Read in all formulas on the created sheet (no formula appears as "" e.g. nullstring).
var formulas = copy.getDataRange().getFormulas();
formulas.forEach(function (row, r) {
row.forEach(function (formula, c, rowData) {
if (!formula) return;
// Check if this is a formula we want to replace.
if (/* your tests here */) {
// Store R1C1 notation for later reading.
toRead.push(String(r + 1) + String(c + 1));
}
}); // End column value checking
}); // End sheet row checking
// If all formulas checked out, quit.
if (toRead.length === 0)
return;
// Read desired values into a RangeList.
var rangeList = source.getRangeList(toRead);
var toWrite = rangeList.getRanges().map(function (range) {
return range.getValue();
});
// Write to the same regions in the destination.
dest.getRangeList(toRead).getRanges().forEach(function (range, i) {
range.setValue(toWrite[i]);
});
}
Если вы знаете структуру / расположение того, что будет действительным / недействительным, вы сможете усовершенствовать этот метод путем пакетного чтения и записи статических значений.