• This repository has been archived on 12/Jan/2018
  • Stars
    star
    1,068
  • Rank 43,257 (Top 0.9 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 15 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

This Project Has Moved!

Python DocX is now part of Python OpenXML. There's all kinds of new stuff, including Python 3 support, sister libraries for doing Excel files, and more. Check out the current Python DocX GitHub and the current Python DocX docs.

Info below is kept for archival purposes. Go use the new stuff!

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

More Repositories

1

powershell-profile

Mike's Powershell Profile (and how to set up Windows console if you've been using *nix for 20 years)
PowerShell
384
star
2

compact-wsl2-disk

A small script for Windows 10 Home users to compact their WSL2 disks
PowerShell
233
star
3

outdated-browser-rework

Detects outdated browsers and advises users to upgrade to a new version. Handles mobile devices!
JavaScript
224
star
4

how-to-install-a-linux-development-environment-on-windows

How to install a Linux development environment on Windows using Ubuntu and WSL2
117
star
5

agave

Cleaner, simpler JavaScript for ES6
JavaScript
115
star
6

serverless-starter-kit

A fulllstack serverless app using TypeScript, Svelte and Architect Serverless
TypeScript
67
star
7

stickers

Various stickers I made, printed and gave away at jsconf 2015
63
star
8

whois-json

Whois with results in actual, structured, camelCased JavaScript!
JavaScript
62
star
9

styleselect

Simple, standalone styling for select boxes in modern browsers.
JavaScript
37
star
10

dynamic-template

Simple dynamic ES6 templates
JavaScript
22
star
11

eyes

Removes eyes from the internet
JavaScript
15
star
12

sorts

JavaScript
15
star
13

eslint-plugin-must-use-await

Flags use of callback functions and .then(), for users of ES2017's async/await
JavaScript
11
star
14

kind.js

Return the kind of a JS object (the same as what a human would).
JavaScript
9
star
15

amps-in-the-trunk

Transform HTML directly to Google AMP HTML
JavaScript
8
star
16

companies-house

A JavaScript client for the Companies House API
JavaScript
7
star
17

pyfilter

Python client for pifilter adult image detection service (www.pifilter.com). Useful for helping automate moderation on public forums.
7
star
18

sass-npm

Import SASS files from npm modules
JavaScript
7
star
19

express-geoip

Express 4 middleware to add req.countryCode, which is the ISO alpha 2 country code, to requests.
JavaScript
6
star
20

is-gmail-account-valid

Find out if a gmail address is used or not
JavaScript
5
star
21

boilerplatejs

JavaScript
4
star
22

pr-chart

Simple AWS SAM / TypeScript / Arc / Svelte app
TypeScript
3
star
23

aoftmurmurkeys

Start and pause A Soft Murmur using the F5 key on your keyboard.
JavaScript
3
star
24

japanese_mayonnaise

Minimal Chrome extension. Removes animated notification area from Google search results.
JavaScript
2
star
25

epilepsy

Make your own Enter the Void style credits. With apologies to Tom Kan.
JavaScript
2
star
26

meatspace-enterprise-edition

JavaScript
2
star
27

devils_pie

A tool to solve the 10 Fast Finger Speedtest http://speedtest.10fastfingers.com/
JavaScript
2
star
28

ringespiel.js

A modern carousel for JQuery
JavaScript
2
star
29

express-middleware-to-async

Express to Arc middleware converter (Experimental)
JavaScript
2
star
30

jquery-html5-validity

JavaScript
2
star
31

imeveryone

Realtime anonymous communication platform
Python
2
star
32

solana-basics-for-everyone

The Keynote Presentation from my Solana Basics for Everyone presentation at Breakpoint 2023.
1
star
33

burn-everything-down

JavaScript
1
star
34

rolex

A better 'watch'
JavaScript
1
star
35

scalpels-and-aks

JavaScript
1
star
36

dotfiles

Mike's dotfiles.
Shell
1
star
37

staring_and_slurping

Starts/stops Soundcloud using the F5 key on your Mac
JavaScript
1
star
38

chrome-bluetooth

Chrome Bluetooth test
JavaScript
1
star
39

emptiness.js

JavaScript
1
star
40

formsed

A simple Chrome extension to quickly search/replace form data automatically when matched URLs are hit.
JavaScript
1
star
41

boring-config

Load a CSON config file
JavaScript
1
star
42

goodbye_horses

High performance CMS
JavaScript
1
star
43

london-javascript-events

List of all JavaScript events in London
1
star
44

minimal-messaging-extension

A minimal manifest v3 extension using chrome.runtime.sendMessage()
JavaScript
1
star
45

nodeplayground

A personal scratch playground for testing ideas in Node JS
1
star
46

quaderno-server

Helps calculate JSON web tokens (JWTs) for one-off charges in Quaderno.
JavaScript
1
star
47

rejectjs2013

Welcome our new ES5 Overlords
JavaScript
1
star
48

goodbye-horses

JavaScript
1
star
49

guetta

Adds additional David Guetta to websites
CoffeeScript
1
star