Questions tagged [python-docx]

A python library to create, read and write Microsoft Office Word 2007 docx files.

The docx module creates, reads and writes Microsoft Office Word 2007 docx files.

Including the following features:

Creation:

  • Paragraphs
  • Bullets
  • Numbered lists
  • Document properties (author, company, etc)
  • Multiple levels of headings
  • Tables
  • Section and page breaks
  • Images

Modification:

  • Search and replace
  • Extract plain text of document
  • Add and delete items anywhere within the document
  • Change document properties
  • Run xpath queries against particular locations in the document - useful for retrieving data from user-completed templates.

For detailed information and examples, visit the python-docx documentation.

See also the official GitHub homepage.

1026 questions
107
votes
9 answers

When import docx in python3.3 I have error ImportError: No module named 'exceptions'

when I import docx I have this error: >File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docx-0.2.4-py3.3.egg/docx.py", line 30, in from exceptions import PendingDeprecationWarning ImportError:…
user3472559
  • 1,181
  • 2
  • 7
  • 3
53
votes
8 answers

How to extract text from an existing docx file using python-docx

I'm trying to use python-docx module (pip install python-docx) but it seems to be very confusing as in github repo test sample they are using opendocx function but in readthedocs they are using Document class. Even they are only showing how to add…
Nancy
  • 657
  • 1
  • 7
  • 12
40
votes
8 answers

How to use python-docx to replace text in a Word document and save

The oodocx module mentioned in the same page refers the user to an /examples folder that does not seem to be there. I have read the documentation of python-docx 0.7.2, plus everything I could find in Stackoverflow on the subject, so please believe…
user2738815
  • 926
  • 2
  • 11
  • 19
21
votes
3 answers

Python-docx, how to set cell width in tables?

How to set cell width in tables?, so far I got: from docx import Document from docx.shared import Cm, Inches document = Document() table = document.add_table(rows=2, cols=2) table.style = 'TableGrid' #single lines in all cells table.autofit =…
girdeux
  • 375
  • 1
  • 3
  • 10
19
votes
2 answers

Is there any way to read .docx file include auto numbering using python-docx

Problem statement: Extract sections from .docx file including autonumbering. I tried python-docx to extract text from .docx file but it excludes the autonumbering. from docx import Document document = Document("wadali.docx") def…
wadali
  • 1,931
  • 16
  • 36
18
votes
2 answers

Converting docx to pdf with pure python (on linux, without libreoffice)

I'm dealing with a problem trying to develop a web-app, part of which converts uploaded docx files to pdf files (after some processing). With python-docx and other methods, I do not require a windows machine with word installed, or even libreoffice…
Ofer Sadan
  • 8,518
  • 4
  • 23
  • 51
18
votes
5 answers

Add an image in a specific position in the document (.docx)?

I use Python-docx to generate Microsoft Word document.The user want that when he write for eg: "Good Morning every body,This is my %(profile_img)s do you like it?" in a HTML field, i create a word document and i recuper the picture of the user from…
Kais Dkhili
  • 339
  • 1
  • 4
  • 18
16
votes
7 answers

combine word document using python docx

I have few word files that each have specific content. I would like for a snippet that show me or help me to figure out how to combine the word files into one file, while using Python docx library. For example in pywin32 library I did the…
omri_saadon
  • 8,823
  • 5
  • 25
  • 53
13
votes
3 answers

How to setup cell borders with python-docx

I need to setup cells borders in table with python-docx, but can't find how to. Please help.
Valentin
  • 131
  • 1
  • 1
  • 3
13
votes
2 answers

Modify docx page margins with python-docx

I need to quickly change the margins of many docx documents. I checked python-docx and I do not find a way to access/modify the page layout (in particular the margins) properties. Is there a way?
XAnguera
  • 967
  • 1
  • 8
  • 22
12
votes
2 answers

Write text in particular font color in MS word using python-docx

I am trying to write text in an MS Word file using python library python-docx. I have gone through the documentation of python-docx's font color on this link and applied the same in my code, but am unsuccessful so far. Here is my code: from docx…
troy_achilies
  • 424
  • 1
  • 5
  • 14
12
votes
4 answers

Python docx Replace string in paragraph while keeping style

I need help replacing a string in a word document while keeping the formatting of the entire document. I'm using python-docx, after reading the documentation, it works with entire paragraphs, so I loose formatting like words that are in bold or…
Alo
  • 796
  • 2
  • 6
  • 23
12
votes
1 answer

Parsing of table from .docx file

I want to parse a table from a .docx file using Python and python-docx into some useful data structure. The .docx file contains only a single table in my case. I've uploaded it so you can have a look. Here's a screenshot:
Sreedhar
  • 187
  • 1
  • 2
  • 8
11
votes
1 answer

python -docx to extract table from word docx

I know this is a repeated question but the other answers did not work for me. I have a word file that consists of one table. I want that table as an output of my python program. I'm using python 3.6 and I have installed python -docx as well. Here is…
Aroon
  • 886
  • 1
  • 13
  • 28
11
votes
1 answer

When using Python docx how to enable spelling in output document?

I'm using the Python docx library to generate an document, that I would like to be able to open and find spelling errors in. But when I open the document none of the spelling errors flag (little red underlines) or are identified if I run a spell…
Colin Talbert
  • 424
  • 6
  • 19
1
2 3
68 69