def testnewdocument(): '''Test that a new document can be created''' docx = Docx() docx.coreproperties('Python docx testnewdocument', 'A short example of making docx from Python', 'Alan Brooks', ['python', 'Office Open XML', 'Word']) docx.savedocx(TEST_FILE)
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')