Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python docx : Line by line reading of Word document

In Python is there a easy way to read a word document line by line. I would like to preserve the formatting while reading the line and copy to other doc after modifying some text.

I can see there is only paragraph reading but no line reading available in docx library.

like image 793
sonicSonar Avatar asked Mar 08 '23 00:03

sonicSonar


1 Answers

Try this:-

import docx
doc = docx.Document('your file')
for i in doc.paragraphs:
    print(i.text)
like image 81
Narendra Avatar answered Mar 21 '23 06:03

Narendra