0

I would like to add a newline in a cell using ExcelJS (using the newest version 4.4).

I have tested with \r\n, \r and \n and all of them gives me the same results: The newline is visible in the formula-bar, but not directly in the cell itself. It displays it in the cell after you manually click on the formula bar.

My question is: Can this be resolved, if yes, how?

Example

In Typescript using the newline commands:

Using the newline commands

How it is visible in Excel:

Results in Excel

Please note that in the formula bar it is displayed correctly.

When clicking in the Formula bar and next clicking to another cell it shows this:

Results in Excel after clicking the formula bar

Any ideas how this can be resolved so the newline is immediately visible in the cell itself?

2
  • Could you apply "wrap text" formatting to the cells which will have new lines and see? When text is manually entered with a newline, it wraps automatically, but, for example, with ="ab" & CHAR(10) & "cd" it does't until "wrap text" is set. Commented Oct 31, 2024 at 12:34
  • You are right nkavli, it does the trick. I shall comment this as an answer 👍🏻. Commented Oct 31, 2024 at 14:53

1 Answer 1

3

As nkavli already commented:

In the documentation in GitHub for ExcelJS you can use:

// set cell to wrap-text
ws.getCell('D1').alignment = { wrapText: true };

And voila: the result is displayed correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.