I like to read a range of data in Google sheet using scripts, modify the data and then write it back.
var range = sheet.getDataRange();
var values = range.getValues();
// modify the values
range.setValues(values);
So far so good, but my sheet also contains formulas which now are replaced with fixed values so modified my code:
var range = sheet.getDataRange();
var values = range.getValues();
var formulas = range.getFormulas();
// modify the values
range.setValues(values);
range.setFormulas(formulas);
But now all my data gets cleared on setFormulas() and I'm struggling to solve this problem nicely. The main reason for my approach is to have the script run fast, as there is lots of data in the sheet.
I.e. I only modify some data, but wish to keep the formulas.