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
0 answers

I have a word document and while reading the it in python, facing fldchar attribute error

The word document I am trying to read contains hyperlinks, colored text etc. At few hyperlinks are giving the following error. When I remove the hyperlinks using manually "Remove Hyperlinks" option by opening the word file and saving it back, it…
Rohit Kumar Singh
  • 647
  • 1
  • 7
  • 17
-1
votes
1 answer

How to draw MS Charts in python-docx?

I am trying to automate some reports using python-docx. For now, I am using matplotlib to draw the graphs and save them as .jpg, before adding them to the document. But I would like to have the ability to edit the charts from inside the Word…
benkyou
  • 61
  • 5
-1
votes
1 answer

Saving docx to a folder in project directory

Project structure I am trying to save created docx document into folder ResumeTemplates, but the program tells me that there's no such file or directory. Anyone know what I am doing wrong in writing the directory? I'm not familiar with a specific…
-1
votes
2 answers

i want to replace ‘ and ’ with ' in html using python. i tried multiple ways but failed

I wrote a code that converts a Word document to HTML using pypandoc because I even want images in that. The problem is my docx file contains characters ‘ and ’ which turn into something different in HTML when sent as a mail body. I want ‘ and ’ to…
-1
votes
1 answer

Make the header only appearing in the first page

I want to put an image on the top of the first page of the document so I pit on header now it's appearing on the rest of the pages would anyone propose another solution or how adapt it so it won't appear on the rest if the pages I am using docx on…
-1
votes
1 answer

docx to pdf conversion working locally when called from flask function but doesn't work on deployment server

I have a flask app that contains a function to create a docx document then converts it to pdf, when i run the code on my local machine everything works fine and the pdf document is created but when i host the app on IIS on deployment machine with…
baraatemp
  • 5
  • 4
-1
votes
1 answer

How to write at a specific position in a WORD file

I have this piece of code that creates for each picture in a folder, a table and a picture in word file. I am using docx library with python in order to do so. The code works but it adds everything at the end of my file. What I am trying to figure…
clemdcz
  • 99
  • 7
-1
votes
1 answer

Delete last line from multiple docx files in python

I want to delete text of multiple docx file using python language. Let's say the contents of a file are: This is line 1 This is line 2 This is line 3 This is line 4 I want to delete the very last line only i.e. This is line 4. I've tried many code…
-1
votes
1 answer

Why does my string color in python-docx not change

My problem is that my string color does not change, The strings name is "TitluCentru". I need to set the color to light blue. import docx from docx.enum.text import WD_ALIGN_PARAGRAPH doc = docx.Document() TitluCentru =…
user14633516
-1
votes
1 answer

python-docx find font of file docx

i need to display all the fonts contained in the docx file. example: In my file has 3 lines of font : calibri , Times New Roman, Arial. I use this code but it only shows the first font it encounters: import docx doc = Document('path of file…
-1
votes
2 answers

how can i know the path of a file created by os.makedirs() and store it in a variable for later use?

i want to build a function that convert names from csv to a document in word by docx library and i want to create an empty file with os.makedirs(), the file is created but i cant get its path to later join path with word document to save the…
-1
votes
1 answer

How to check if a docx or doc file is empty

I have a script that can convert a docx file to a json and I was wondering how can I detect if a file is empty. A solution I found is that one: https://thispointer.com/python-three-ways-to-check-if-a-file-is-empty/ Using: os.stat(file_path).st_size…
-1
votes
1 answer

Getting error while trying "pip install python-docx" in pycharm terminal

New to python and just trying pip install python-docx and getting this message: Command "C:\Users\samue\PycharmProjects\testings\venv\Scripts\python.exe -u -c "import setuptools,…
Samuel
  • 1
-1
votes
1 answer

Python input interface with multiple fields that can be edited before submitting

In Python, is it possible to have multiple input() fields that all can be edited before submitting to define variables, like a form? For example: var1 = input('num1: ') var2 = input('num2: ') var3 = input('num3: ') When I run this code I have to…
robopyot
  • 21
  • 2
-1
votes
1 answer

Python - Replacing String With Images In docx

I have been trying for a while to replace certain image strings located in cells in a table in a docx file with the related images located in a folder. Let a compiled list of all images = Images. My 'best' attempt so far is to iterate through all…
Fonti
  • 133
  • 1
  • 9