Example #1
0
def simpledoc():
    '''Make a docx (document, relationships) for use in other docx tests'''
    docx = Docx()
    docx.heading('Heading 1', 1)  
    docx.heading('Heading 2', 2)
    docx.paragraph('Paragraph 1')
    for point in ['List Item 1', 'List Item 2', 'List Item 3']:
        docx.paragraph(point, style='ListNumber')
    docx.pagebreak(type='page')
    docx.paragraph('Paragraph 2')
    docx.table([['A1', 'A2', 'A3'], ['B1', 'B2', 'B3'], ['C1', 'C2', 'C3']])
    docx.pagebreak(type='section', orient='portrait')
    docx.picture(IMAGE1_FILE, 'This is a test description')
    docx.pagebreak(type='section', orient='landscape')
    docx.paragraph('Paragraph 3')
    return docx
Example #2
0
def simpledoc():
    '''Make a docx (document, relationships) for use in other docx tests'''
    docx = Docx()
    docx.heading('Heading 1', 1)
    docx.heading('Heading 2', 2)
    docx.paragraph('Paragraph 1')
    for point in ['List Item 1', 'List Item 2', 'List Item 3']:
        docx.paragraph(point, style='ListNumber')
    docx.pagebreak(type='page')
    docx.paragraph('Paragraph 2')
    docx.table([['A1', 'A2', 'A3'], ['B1', 'B2', 'B3'], ['C1', 'C2', 'C3']])
    docx.pagebreak(type='section', orient='portrait')
    docx.picture(IMAGE1_FILE, 'This is a test description')
    docx.pagebreak(type='section', orient='landscape')
    docx.paragraph('Paragraph 3')
    return docx
Example #3
0
If you need to make documents from scratch, you can use this file as a basis
for your work.

Part of Python's docx module - http://github.com/mikemaccana/python-docx
See LICENSE for licensing information.
"""

from docx import Docx

if __name__ == '__main__':
    # Make a new document tree - this is the main part of a Word document
    docx = Docx()

    # Append two headings and a paragraph
    docx.heading("Welcome to Python's docx module", 1)
    docx.heading('Make and edit docx in 200 lines of pure Python', 2)
    docx.paragraph('The module was created when I was looking for a '
        'Python support for MS Word .doc files on PyPI and Stackoverflow. '
        'Unfortunately, the only solutions I could find used:')

    # Add a numbered list
    points = [ 'COM automation'
             , '.net or Java'
             , 'Automating OpenOffice or MS Office'
             ]
    for point in points:
        docx.paragraph(point, style='ListNumber')
    docx.paragraph('For those of us who prefer something simpler, I '
                          'made docx.')
    docx.heading('Making documents', 2)