For questions that are not specific to web2py, you might have more success 
on Stack Overflow or a forum dedicated to the specific library/topic of 
your question. In this case, it appears that replacing the text of an 
entire paragraph removes the Run-level formatting (though not the 
paragraph-level formatting). Instead, you probably need to replace the text 
of the relevant Run within the paragraph (which will preserve the Run-level 
formatting).

Anthony

On Saturday, July 11, 2015 at 9:24:03 AM UTC-4, M S Pangtey wrote:
>
> Hi, I am facing problem in formatting Docx file using python docx library.
> I am able to replace some paragraph text but not able to maintain text 
> font and font weight. Below is the pseudo code for this 
>
> from docx import Document
>
> # read doc file
> doc = Document(file name)
>
> # now I need to replace few words in a paragraph,(lets say I want to 
> replace a key in the paragraph by val) and paragraph index (pid) is known.
>
> paragraph = doc.paragraphs[int(pid)].text
>
> para = re.sub(key, val, paragraph.rstrip())  
> doc.paragraphs[pid].text = para
>
> # So 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.
>
> I want to maintain the fort "Times New Roman" in the document. How to do 
> that?
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to