O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required