def testunsupportedpagebreak(): '''Ensure unsupported page break types are trapped''' docx = Docx() try: docx.pagebreak(type='unsup') except ValueError: return # passed assert False # failed
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
print 'Searching for something in a paragraph ...', if docx.search('the awesomeness'): print 'found it!' else: print 'nope.' print 'Searching for something in a heading ...', if docx.search('200 lines'): print 'found it!' else: print 'nope.' print 'Replacing ...', docx.replace('the awesomeness', 'the goshdarned awesomeness') print 'done.' # Add a pagebreak docx.pagebreak(type='page', orient='portrait') docx.heading('Ideas? Questions? Want to contribute?', 2) docx.paragraph('Email <*****@*****.**>') docx.coreproperties(title='Python docx demo', subject='A practical example of making docx from Python', creator='Mike MacCana', keywords= ['python', 'Office Open XML', 'Word']) # Save our document docx.savedocx('Welcome to the Python docx module.docx')