GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - gtozzi/python-docx: Reads, queries and modifies Microsoft Word 2007/2008 docx files.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

144 Commits
144 Commits

Folders and files

NameName
Last commit message
Last commit date
template
template
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
HACKING.markdown
HACKING.markdown
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.markdown
README.markdown
 
 
SERVING_SUGGESTIONS.markdown
SERVING_SUGGESTIONS.markdown
 
 
__init__.py
__init__.py
 
 
docx.py
docx.py
 
 
example-compiletemplate.py
example-compiletemplate.py
 
 
example-extracttext.py
example-extracttext.py
 
 
example-makedocument.py
example-makedocument.py
 
 
example-template.docx
example-template.docx
 
 
image1.png
image1.png
 
 
screenshot.png
screenshot.png
 
 
setup.py
setup.py
 
 

Repository files navigation

Python docx

Introduction

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

These are referred to as 'WordML', 'Office Open XML' and 'Open XML' by Microsoft.

These documents can be opened in Microsoft Office 2007 / 2010, Microsoft Mac Office 2008, Google Docs, OpenOffice.org 3, and Apple iWork 08.

They also validate as well formed XML.

The module was created when I was looking for a Python support for MS Word .doc files, but could only find various hacks involving COM automation, calling .net or Java, or automating OpenOffice or MS Office.

The docx module has the following features:

Making documents

Features for making documents include:

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

Editing documents

Thanks to the awesomeness of the lxml module, we can:

  • 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.

Getting started

Making and Modifying Documents

  • Just download python docx.
  • Use pip or easy_install to fetch the lxml and PIL modules.
  • Then run:
example-makedocument.py

Congratulations, you just made and then modified a Word document!

Extracting Text from a Document

If you just want to extract the text from a Word file, run:

example-extracttext.py 'Some word file.docx' 'new file.txt' 

Ideas & To Do List

  • Further improvements to image handling
  • Document health checks
  • Egg
  • Markdown conversion support

We love forks, changes and pull requests!

  • Check out the HACKING to add your own changes!
  • For this project on github
  • Send a pull request via github and we'll add your changes!

Want to talk? Need help?

Email [email protected].

License

Licensed under the MIT license Short version: this code is copyrighted to me (Mike MacCana), I give you permission to do what you want with it except remove my name from the credits. See the LICENSE file for specific terms.

About

Reads, queries and modifies Microsoft Word 2007/2008 docx files.

Resources

Readme
MIT license
Activity

Stars

4 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.