Putting It Together

Now we can build a set of management accounts. The example applications include a Word template, an Excel spreadsheet with a prebuilt chart, and a test routine in easyword.py. Thanks to helper methods, this is simple:

def test():
    outfilename = MYDIR + '\\pythonics_mgt_accounts.doc'
    
    w = WordWrap(MYDIR + '\\pythonics.dot')
    w.show()  # leave on screen for fun
    w.addStyledPara('Accounts for April', 'Title')
    
    #first some text
    w.addStyledPara("Chairman's Introduction", 'Heading 1')
    w.addStyledPara(randomText(), 'Normal')
    
    # now a table sections
    w.addStyledPara("Sales Figures for Year To Date", 'Heading 1')
    data = randomData()
    w.addTable(data, 37) # style wdTableStyleProfessional
    w.addText('\n\n')
    
    # finally a chart, on the first page of a ready-made spreadsheet
    w.addStyledPara("Cash Flow Projections", 'Heading 1')
    w.addInlineExcelChart(MYDIR + '\\wordchart.xls', 'Cash Flow Forecast')
       
    w.saveAs(outfilename)
    print 'saved in', outfilename

This runs visibly for fun, but would be much faster if kept off-screen. It produces the document in Figure 10.3.

The finished document
Figure 10.3. The finished document

Get Python Programming On Win32 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.