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.

Available from pypi.

See also the official GitHub homepage.

1408 questions
-1
votes
1 answer

Facing issues while trying to access a file of type docx stored in aws-s3 bucket with the help of python-docx

I have a docx file at my aws-s3 bucket. I need to read it use python-docx. I write this: from docx import Document document = Document('https://my-first-backup-bucket-v1.s3-ap-southeast-1.amazonaws.com/New+Proposed+Quote.docx') then, have error..…
GOPI M
  • 27
  • 7
-1
votes
1 answer

How to generate a pdf file using Word Template in Python?

I need to generate the pdf file in Python. I have created a Word Template file (Word XML document) with placeholders in the document. I populate the placeholders dynamically and can create a word document. However, I would like to convert this…
Kiran
  • 8,034
  • 36
  • 110
  • 176
-1
votes
1 answer

python-docx: Find the heading name in which a table lies inside a ms word document

I'm struggling to find the heading name in which a table lies, I'm using python-docx library, I'd like to know the possibility I can use to get the table along its heading name in which it lies inside. from docx import Document from docx.shared…
Ali Asad
  • 1,235
  • 1
  • 18
  • 33
-1
votes
1 answer

How can I batch this code on a folder of word files?

I have a developed a piece of code that I would like to run on a folder of docx files. I have successfully figured out how I can run this on one file (see code below) but am too green to figure out how to batch this. I would like to write all docx…
-1
votes
1 answer

How to generate a table with varying size of rows in Python?

I am trying to automate the generation of a report by taking data out of excel and putting into a word document with tables . I know how to read from excel and write to word , but I am trying to generate a specific type of table in the word document…
-1
votes
1 answer

ImportError: cannot import name 'Document'

I ran a code generated in python 3.6.5, it perfectly worked (countless times), now I turned on my computer, runned it again (didn't change anything at all) and: ImportError: cannot import name 'Document' I tried to uninstall docx or python-docx via…
Joe
  • 78
  • 1
  • 7
-1
votes
2 answers

Converting docx table into html (keeping all formatting) or an image to use in html

I've used python-docx to create some tables using a specified style format in my docx file. I now need to use these tables with this same formatting. Is there a way I can either convert the table including all of the formatting and styles, colours…
oben
  • 31
  • 2
  • 5
-1
votes
2 answers

How can I create a word (.docx) document if not found using python and write in it?

How can I create a word (.docx) document if not found using python and write in it? I certainly cannot do either of the following: file = open(file_name, 'r') file = open(file_name, 'w') or, to create or append if found: f = open(file_name,…
sudoCoder
  • 115
  • 2
  • 13
-1
votes
1 answer

How to update content in existing word document using python

I have an existing word document in the below format. 1. Test Case Specification Identifier [test case number] 55-01-01 [title] Login with default [revision history] 2. Test Items [objective] 3. Execution [step 1]…
premganesh
  • 67
  • 1
  • 9
-1
votes
2 answers

Finding length of a document using python docx

I am trying to a loop from the first to last line of a word document. I am using python-docx package. Documents deals with paragraphs & tables as well. What I want to do is: Write a for loop from first to last of the document and do something for…
Nupur B
  • 1
  • 3
-1
votes
1 answer

How can I change letters’ color?

I want to write letters in docx.I wrote codes, from docx import Document document = Document() document.add_heading("TITLE", 1) document.save("test.docx") But when I run the codes, the letter of TITLE is colored blue.I want to add color black to…
user10102827
  • 319
  • 2
  • 7
  • 18
-1
votes
2 answers

Change table length in word-document, python-docx, Python

I can't seem to find a way to change the length f the entire table in a word-document. I have only seen examples of ways to change the columns in the table, not the actual table itself. Would be great if someone could tell me how to do it :) Here is…
Pigfarmer
  • 1
  • 3
-1
votes
1 answer

Print function printing multiple times in python

My script for counting tables and rows in the word docx working well. My question is why my printing statement printing till the condition gets fail. I attached the image for your reference Here is my code: from docx import Document doc =…
Aroon
  • 991
  • 2
  • 15
  • 34
-1
votes
1 answer

How to add pictures to docx python from URL?

I am having trouble with the Python Docx Library, I have scraped images from a website and I want to add them to docx but I cannot add the images to docx directly, I keep getting an error: File "C:\Python27\lib\site-packages\docx\image\image.py",…
-1
votes
3 answers

Inserting txt file info into docx

I am using python 3.5, python-docx, and TKinter. Is there any way to be able to type a .txt file name into an entry box and have python insert the contents of that .txt file into a specific place in docx? I know how to get information from Entry…
Craig Walker
  • 131
  • 2
  • 10