Reputation: 175
I made an application with google drive and sheets api the problem is that the sheet has some formulas that has conflicts with the created api so I was forced to erase the formulas and write a little app script to autofill the formulas. I was following this [tutorial][1]. But as the formula has strings to concat it throws a syntax error. My code is here:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
ss.getRange("I2").setFormula(CONCAT("problem string";"\n";C2;"\n";F2));
}
Do i need to declare the string as a variable?
EDIT: i am also having problems when using the \n new line character [1]: https://www.youtube.com/watch?v=cCBtsQGtzoQ
Upvotes: 0
Views: 1389
Reputation: 27350
setFormula accepts a string but you are passing CONCAT
which is not defined nor it is a built in JavaScript method. To make it a string directly, you can use template literals.
also your formula is wrong because CONCAT
can concatenate only 2
strings, not 5
. You need to use CONCATENATE.
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
ss.getRange("I2").setFormula(`CONCATENATE("problem string";"\n";C2;"\n";F2)`);
}
Output:
Upvotes: 2