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

A

accessnewbie

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.

if Count:
blurb = "\r\nINSERT TABLE HERE\r\n\r\nSA* - South America\r\nNA** - North America\r\nCA*** - Central America"
else:
blurb = ""

further down I also have the following code (a small snippet of actual codefor clarification)

replaceText = {"TEXTBLURB" : blurb}

Right now "if Count" is true, the output in the word document looks like this:

INSERT TABLE HERE SA* - South America NA** - North America CA*** - Central America

I want it too look like this:

INSERT TABLE HERE

SA* - South America
NA** - North America
CA*** - Central America

I have a MS Word template file called "Automated Response.docx" that has a TAG imbedded between two paragraphs called "TEXTBLURB". Using a python script, if a certain condition is met, I want to replace this tag with some text (see above "blurb") that contains newlines, otherwise, don't add the textbetween paragraphs. I can't figure out the python code needed to imbed newlines into the tag.

Ideas as to how to add new lines via python coding? I tried \r, \n, \r\n, ^11
and
. None worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,708
Messages
2,569,347
Members
44,655
Latest member
VinayKumarNevatiia

Latest Threads

Top