This question can be better addressed on the *docx *google group:
https://groups.google.com/forum/#!forum/python-docx. You could also drop
an email: python-d...@googlegroups.com
<mailto:python-docx%40googlegroups.com>
________________________________________
Kiran Subbaraman
http://subbaraman.wordpress.com/about/
On Mon, 13-07-2015 11:11 AM, M S Pangtey wrote:
Hi, I am facing problem in formatting Docx file using python docx library.
I am able to replace some text in a paragraph but can't maintain text
font.
from docx import Document
# read doc file
doc = Document(file name)
# now I need to replace few words in a paragraph,(lets say replace a
key in the paragraph by val) and paragraph index(pid) is known so I
am performing following tasks:
paragraph = doc.paragraphs[int(pid)].text
para = re.sub(key, val, paragraph.rstrip())
doc.paragraphs[pid].text = para
# After saving this document, now I can see replaced text in the file
but not able to maintain the font. I mean earlier common font in the
file was "Times New Roman" but after text replacement paragraph font
and weight is different. So how can I maintain the paragraph font and
other styling similar to before text replacement.
Or how to extract the existing font!!!
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google
Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to web2py+unsubscr...@googlegroups.com
<mailto:web2py+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.