Python Forum
How to add run in paragraph using python-docx?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add run in paragraph using python-docx?
#1
I want to put runs in one paragraph to another using , so I write code like this: But it does not work. How should I change this code?

from docx import Document
import re
                                                                                                                                                 
master = Document("out.docx")
po = master.add_paragraph('It is: ')
doc = Document("in4.docx")
for p in doc.paragraphs:
    if re.search('yyy', p.text):
        for r in p.runs:
            master.paragraphs[-1].runs.append(r)
master.save('out1.doc1')    
Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  no module named 'docx' when importing docx MaartenRo 1 716 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  Replace a text/word in docx file using Python Devan 4 2,859 Oct-17-2023, 06:03 PM
Last Post: Devan
  docx insert words of previuos paragraph on next paragraph in the same position ctrldan 7 1,170 Jun-20-2023, 10:26 PM
Last Post: Pedroski55
  python-docx: preserve formatting when printing lines Tmagpy 4 2,009 Jul-09-2022, 01:15 AM
Last Post: Tmagpy
  python-docx- change lowercase to bold, italic Tmagpy 0 1,353 Jul-01-2022, 07:25 AM
Last Post: Tmagpy
  python-docx regex : Browse the found words in turn from top to bottom Tmagpy 0 1,492 Jun-27-2022, 08:45 AM
Last Post: Tmagpy
  python-docx regex: replace any word in docx text Tmagpy 4 2,140 Jun-18-2022, 09:12 AM
Last Post: Tmagpy
  Сombine (Merge) word documents using python-docx Lancellot 1 11,362 May-12-2021, 11:07 AM
Last Post: toothedsword
  How to use python to convert pdf to docx impact_code 3 2,592 Aug-01-2020, 01:58 PM
Last Post: Yoriz
  Extracting parts of paragraphs from word documents using python-docx library & lists Den0st 0 10,439 Nov-06-2019, 12:07 AM
Last Post: Den0st

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020