Newline in openxlsx2 #376
JanMarvin
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Whenever I search for
openxlsx
on stackoverflow, this problem pops up: Newline in openxlsx. Well, let's answer the problem in anopenxlsx2
way. All you need to know: The visual effect that tells the spreadsheet software to break the row in the cell for you is a cell style. If you omit this and simply writea\nb
, the line will wrap in the formula editor, but not visually in the spreadsheet.Background
Line breaks in open xml require the
wrapText
style element. It looks like this when written from MS365.When written from
openxlsx2
it looks like this (we might align it in upcoming releases).Code example
The style that creates line breaks is not applied by default. Therefore, each time a line break is desired, the "wrapText" cell style must be added manually. If we had to automate this, we'd have to search for "\n" in every string we add to a workbook.
Fortunately, it is quite easy to add the "wrapText" option to a cell style.
Beta Was this translation helpful? Give feedback.
All reactions