SOLVED

Enter newlines in a cell by JavaScript API

Brass Contributor

When editing a string value in a cell, we could well use Alt+Enter to enter a newline.

However, when we write a string into a cell by JavaScript, newlines (i.e., `\n`) are ignored. I'm trying the following custom function, we see that what is displayed in the cell does not have newlines.

 

 

/**
* Test2
* @customfunction
* @param {number} a number
* @returns {string} the result
*/
function Test2(n) {
const xxx = "11111\n22222\t33333\r44444 55555"
console.log(xxx)
return xxx
}

 

 

Screenshot 2021-07-30 at 15.10.14.png

 

Does anyone know how to enter newlines into a cell by JavaScript API? Is there any workaround?

2 Replies
best response confirmed by Tie CHENG (Brass Contributor)
Solution

@Tie CHENG 

Has 'Wrap Text' been turned on for the cell with the formula?

Wow, indeed, thank you...
1 best response

Accepted Solutions
best response confirmed by Tie CHENG (Brass Contributor)
Solution

@Tie CHENG 

Has 'Wrap Text' been turned on for the cell with the formula?

View solution in original post