Skip to main content

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

Project description

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

http://github.com/mikemaccana/python-docx/raw/master/screenshot.png

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](HACKING.markdown) 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 python-docx@googlegroups.com

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docx-0.2.4.tar.gz (54.9 kB view details)

Uploaded Source

File details

Details for the file docx-0.2.4.tar.gz.

File metadata

  • Download URL: docx-0.2.4.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for docx-0.2.4.tar.gz
Algorithm Hash digest
SHA256 9d7595eac6e86cda0b7136a2995318d039c1f3eaa368a3300805abbbe5dc8877
MD5 9ef0cd4157edcf37ee789bc0f98a9114
BLAKE2b-256 4a8e5a01644697b03016de339ef444cfff28367f92984dc74eddaab1ed60eada

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page