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

How to write to a open Word Document

I wish to be able to write to an open word document using python-docx. However this throws a IOError: [Errno 13] Permission denied: 'test.docx' which i had kind of suspected due to similar cases in the past, but i would like to be able to alter the…
john hon
  • 103
  • 2
  • 2
  • 7
-1
votes
1 answer

How to color text to later be put in a docx file?

I want to color a text present in the string and pass the string to another python file so that to put received colored string into a docx file. I tried in this way but it is not working. from termcolor import colored from docx import…
Rejo Varghese
  • 67
  • 2
  • 9
-1
votes
1 answer

insert annotation to a word document by using POI or DOCX4J

I'd like to insert some annotations into work documents by using Java or Python. I tried POI, DOCX4J and python-docx. But unfortunately until now I didn't figure out how to use them to generate annotation in a word document. Any advice would be…
S.SMITH
  • 11
-1
votes
1 answer

Installing Docxfactory in python

I am trying to install the package Docxfactory to use in python. I am pretty new to python and I have had about 50/50 success with installing packages... For this one when I use pip as in pip install docxfactory it says "Could not find a version…
McHenry
  • 229
  • 2
  • 8
-1
votes
1 answer

How do I embed a csv file into a Word Document with Python docx

I'm opening a docx file and I want to embed into it a csv file. The csv should be displayed as an icon. How would I set it's ecaxt position in my Word File? My code so far is: from Tkinter import Tk from tkFileDialog import askopenfilename import…
Kyriakos
  • 11
  • 1
  • 3
-2
votes
1 answer

How can i create table using Docxptl in Python?

I want to create a table using docxtpl in python, where the table rows should be dynamic For eg: user_dict = [{"name": "Person 1", "age": 25, "job": "Software Engineer"}, {"name": "Person 1", "age": 25, "job": "Software Engineer"}, …
-2
votes
1 answer

How to save python docx on client side using ajax?

I use python 3.6 Django, my code looks like this: from docx import Document document = Document() document.add_heading('My docx', 0) document.save('myFile.docx') return HttpResponse(document, content_type='application/vnd') I don't want to save…
Nesi
  • 19
  • 5
-2
votes
1 answer

how can i import Document in python module docx?

I'm using mac and installing python-docx using pip. I went into C:\Python27\Scripts and ran pip install python-docx I thought it should have been installed. But when i run a simple import from docx import Documents it ran into an ImportError: No…
-2
votes
1 answer

How to insert a paragraph before TOC (Table of contents)

I am trying to insert a paragraph before TOC using python-docx. Is there a way in which I can add the paragraph before the TOC. This is what currently I have I want something like this
-2
votes
2 answers

Why python-docx?

import docx import collections listofnames = list() filename = 'Missing_Assignments.docx' filehandle = docx.Document(filename) studentinfo = filehandle.paragraphs for student in studentinfo: if len(student.text) > 1 or len(student.text) > 20: …
James Norris
  • 33
  • 1
  • 5
-2
votes
1 answer

AttributeError: 'str' object has no attribute 'add_picture'

I need to insert a picture(png format and named as {number2}.png) in the word(named as {number2}.docx), but it doesn't work and shows this error, someone can help me?enter image description here
Danny
  • 3
  • 2
-2
votes
1 answer

How to get aligment of text?

I use ooxml.doc.Text, and need to know that text is in a center, left, or in right. In Text i have only these functions/values: 'parent', 'ppr', 'reset', 'rpr', 'text', 'value', in this class not have aligment variable. How I can get that?
-2
votes
1 answer

I can't change the font in python-docx

when I input : from docx.enum Import WD_STYLE_TYPE the output is: from docx.enum import WD_STYLE_TYPE ImportError: cannot import name 'WD_STYLE_TYPE' from 'docx.enum' I already had problems installing python-docx that solved
-2
votes
1 answer

Python3 Docx get text between 2 paragraphs

i have .docx files in a directory and i want to get all text between two paragraphs. Example: Foo : The foo is not easy, but we have to do it. We are looking for new things in our ad libitum way of life. Bar : I want to get : The foo is not…
ricardo
  • 82
  • 1
  • 9
-2
votes
1 answer

Use python-docx to batch process many datum and generate reports. But doc file contains previous data file's analysis results

There is a for loop in my code to go through each data file, and codes to analyze the data(plotting graphs), and then add graphs to the doc file. The doc file always contains previous data's analysis results(the graphs), which isn't what i want. I…
Roy_San
  • 3
  • 1
1 2 3
93
94