Google Apps Script – How to Write Both Values and Formulas

google sheetsgoogle-apps-script

The row in my spreadsheet has format

<value>, <formula>, <value>, <formula>, ...

I need to update this row. Indeed, I can't use range.setFormulas, because it has values and I can't use range.setValues, because it has formulas. The only way I found – to set by one value, but this is very expensive if I have a lot of cols in my sheet.

Is there any way to set both formulas and values in one network request?

PS. To set value via setFormula('"' + str + '"') is not very good idea

Best Answer

I can't use range.setFormulas, because it has values and I can't use range.setValues, because it has formulas

Wrong, just use setValues and if it is a formula add an equal sign to the beginning...

https://developers.google.com/apps-script/reference/spreadsheet/range#setvaluevalue