I'm trying to create a odt document by using PyQt4. The document involves inserting multiple lines text into cells. My example code:
from PyQt4 import QtGui
doc = QtGui.QTextDocument()
cur = QtGui.QTextCursor(doc)
table = cur.insertTable(1, 2)
# The cursor is moved to the first cell of the table
cur.insertText("""line 1
line 2""")
writer = QtGui.QTextDocumentWriter()
writer.setFormat(writer.supportedDocumentFormats()[1]) # ODF Format
writer.setFileName('example.odt')
writer.write(doc)
I want 'line 1' and 'line 2' to be in the same cell, but they are in different cells due to the line break. This also had the same effect as the code above:
cur.insertText('line 1\n')
cur.insertText('line 2\n')
Perhaps it’s too late.
If you use chr(10) you insert a line feed. There are two ways to do it.