O'Reilly logo

Python 2.6 Text Processing Beginner's Guide by Jeff McNeil

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

Time for action - generating XLS data

In this example, we'll reuse the Worksheet1.csv file we created in Chapter 4, Text Processing Using the Standard Library. Copy that file over to your current directory now.

  1. Create a new Python file and name it xls_build.py. Enter the following code as follows:
     import csv import sys import xlwt from xlwt.Utils import rowcol_to_cell from optparse import OptionParser def render_header(ws, fields, first_row=0): """ Generate an Excel Header. Builds a header line using different fonts from the default. """ header_style = xlwt.easyxf( 'font: name Helvetica, bold on') col = 0 for hdr in fields: ws.write(first_row, col, hdr, header_style) col += 1 return first_row + 2 if __name__ == '__main__': parser = OptionParser() ...

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