Adding new lines to word document using zipfile module within python 2.7?

Christian Gollwitzer auriocus at gmx.de
Tue Aug 27 17:11:36 EDT 2013


Am 27.08.13 22:45, schrieb accessnewbie at gmail.com:
> Writing text to a word document (word 2007) using the zipfile module
> via python coding (python 2.7). Below if the section of code I am
> using to do this. I can't figure out what character I need to use to
> get it to add new lines to the zipfile.

Word files (2007) are zipped-up XML files. In XML, whitespace is 
ignored, so probably you need some special tag (like <br/> in XHTML) to 
insert the line break.

The easiest way to find this out - short of reading the specs - is to 
open the file in Word, add a line break, save it and then run a diff 
tool over the output and the original file.

If you want to go the specs route instead, you can start here:

	http://en.wikipedia.org/wiki/Office_Open_XML

Christian



More information about the Python-list mailing list