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

jinja table in docx with for and if conditon

I have a table in docx in which i want the rows to be added to table only if the substring exists in the string. have included the image of my template for table here : template for docx table enter image description here i have a dataset x with…
arya nair
  • 1
  • 4
-1
votes
2 answers

Convert the docx file into pdf in python

I am workin on a report generator, and I used pip install python-docx and import docx. Now I have made a new docx file, edited it but I want to save it in pdf instead of docx file. And the program script will be converted into EXE file. Please…
Aryan Jain
  • 13
  • 1
  • 3
-1
votes
1 answer

How can you move text to the end of a line in a docx file using python-docx?

I have text like "word1 word2" and want to change it to "word1_______________word2" (underscores are spaces) Adding just enough spaces to keep word1 and word2 on the same line in a docx file. I'm afraid I don't really have a good idea of a solution…
-1
votes
1 answer

When I save the docx file in python, data gets corrupted

I am able to edit & save txt without problem but when I save the docx file, data gets corrupted. Like the image here: image of error Any suggestions to save docx properly? Thanks. def save(self,MainWindow): if self.docURL == "" or…
Engathin
  • 3
  • 1
-1
votes
1 answer

How I can create TextBox in python-docx?

I need to write some text in TextBox element, to it looks like this How I can make it by python-docx? Or I need to make it by oxml? Thanks!
-1
votes
2 answers

How to get all the text in a nested table using python?

I have to extract all the text in a nested table (tables inside table inside table) from a word document. I'm unable to do it using the python-docx, maybe my lack of knowledge. Please suggest some code examples.
Rabindra
  • 369
  • 4
  • 14
-1
votes
1 answer

how to convert word file into pdf using python?

I tried using pypdf2 but it is not working. import docx from docx2pdf import convert doc = docx.Document() tr_no = "TR9K939393r4" doc.add_paragraph(tr_no) doc.save("E:\Test.docx") convert("E:\Test.docx") convert("E:\Test.docx", "E:\Test.pdf")
-1
votes
2 answers

Change the page color of a word document using python

I created a word document using python and docx module. I want some method to change the background color of the whole document, but I can't find any. Any ideas? from docx import Document document = Document()
-1
votes
1 answer

Problem using XLSX as database in python-docx-template

When I use a XLSX file as database in my python-docx-template, the output file came with bugs. The XLSX file contains: name birth gender Felipe 07/04/1988 male My template in docx contains: My name is {{ name }}, i am {{ gender }}…
-1
votes
1 answer

How to read the text in the shape use python-docx

How to read the text in the shape use python-docx? I have tested the inline_shapes, which is an empty array. The definition of inline_shape has no text either. https://python-docx.readthedocs.io/en/latest/api/shape.html#docx.shape.InlineShapes How…
Carpemer
  • 237
  • 2
  • 9
-1
votes
1 answer

How to import every docx file in a folder into Python?

I'm pretty new to Python and I'm using the Python-docx module to manipulate some docx files. I'm importing the docx files using this code: doc = docx.Document('filename.docx') The thing is that I need to work with many docx files and in order to…
TomasDanke
  • 11
  • 4
-1
votes
1 answer

How i do make this paragraph bold using docx in python

I need to make this paragraph bold but I am not able to do so I used p.bold = True but it did not work I also used add_run for each line but it is showing that int type and bool type do not have any attribute add_run. p =…
Gavya Mehta
  • 211
  • 6
  • 20
-1
votes
2 answers

How to use regular expressions with python docx?

I want to find a specific regex in a docx document. I installed python-docx and I can find strings in my text. However, I want to use regular expressions. So far my code is: import re from docx import Document doc =…
Anna
  • 369
  • 2
  • 10
-1
votes
2 answers

Docx Python - Read line by line

I have the following text in a word file.. I am trying to read the text line by line, check whether the last word is hyphenated, if it is hyphenated then join the last word of the current sentence and first word of the previous sentence without…
-1
votes
1 answer

How to extract text data in a table created in a docx document

I would like to extract text from docx document, I come up with a script extracting text from docx document but I noticed that some document have table and the script do not work on them, How can I improve the above script : import glob import…
kely789456123
  • 605
  • 1
  • 6
  • 21