Python: Is there a way to write multi-line strings into an excel cell with just the xlwt module? (I saw answers suggesting use of openpyxl module)
The sheet.write()
method ignores the \n escape sequence. So, just xlwt, is it possible? Thanks in advance.
I found the answer in the python-excel Google Group. Using
sheet.write()
with the optionalstyle
argument, enabling word wrap for the cell, does the trick. Here is a minimum working example:While in cell A1 shows
HelloWorld
without linebreak, cell B1 showsHello\nWorld
(i.e. with linebreak).There are a few things you could try:
\n
(line feed) character is the standard Unix method and also used in Python, Windows requires a carriage return and line feed. You could therefore try replacing\n
with\r\n
.