Beispiel #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
Beispiel #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
Beispiel #3
0
def testtable():
    '''Ensure tables make sense'''
    docx = Docx()
    testtable = docx.table([['A1', 'A2'], ['B1', 'B2'], ['C1', 'C2']])
    ns = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'
    assert testtable.xpath('/ns0:tbl/ns0:tr[2]/ns0:tc[2]/ns0:p/ns0:r/ns0:t',
                           namespaces={'ns0':'http://schemas.openxmlformats.org/wordprocessingml/2006/main'})[0].text == 'B2'
Beispiel #4
0
def testtable():
    '''Ensure tables make sense'''
    docx = Docx()
    testtable = docx.table([['A1', 'A2'], ['B1', 'B2'], ['C1', 'C2']])
    ns = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'
    assert testtable.xpath(
        '/ns0:tbl/ns0:tr[2]/ns0:tc[2]/ns0:p/ns0:r/ns0:t',
        namespaces={
            'ns0':
            'http://schemas.openxmlformats.org/wordprocessingml/2006/main'
        })[0].text == 'B2'
Beispiel #5
0
    docx.heading('Making documents', 2)
    docx.paragraph('The docx module has the following features:')

    # Add some bullets
    points = ['Paragraphs', 'Bullets', 'Numbered lists',
              'Multiple levels of headings', 'Tables', 'Document Properties']
    for point in points:
        docx.paragraph(point, style='ListBullet')

    docx.paragraph('Tables are just lists of lists, like this:')
    # Append a table
    tbl_rows = [ ['A1', 'A2', 'A3']
               , ['B1', 'B2', 'B3']
               , ['C1', 'C2', 'C3']
               ]
    docx.table(tbl_rows)

    docx.heading('Editing documents', 2)
    docx.paragraph('Thanks to the awesomeness of the lxml module, '
                          'we can:')
    points = [ 'Search and replace'
             , 'Extract plain text of document'
             , 'Add and delete items anywhere within the document'
             ]
    for point in points:
        docx.paragraph(point, style='ListBullet')

    # Add an image
    docx.picture('image2.png', 'This is a test description')

    # Search and replace