Eric Gazoni – Wise Old Geek

Technical Advisor | Software Architect | Open Source Creator

Building useful things for 20 years. Still debugging life.

Month: May 2010

  • openpyxl reaches 1.0 mark

    After a few more efforts, I am pleased to announce the release of the first version of openpyxl.

    The reader and the writer are working and tested for strings and numbers.

    I have been able to read and write simple Excel 2007 xlsx files from Python and open them with Excel.

    You can clone the repository using Mercurial:

    hg clone https://ericgazoni@bitbucket.org/ericgazoni/openpyxl

    or download the release in zip format.

    Edit: 1.0 release is really outdated, you might want to get a more recent version here.

    The (sparse for now) documentation can be found on the wiki.

    Reader usage (using the “empty_book.xlsx” file from the previous example)

    from openpyxl.reader.excel import load_workbook
    
    wb = load_workbook(filename = r'empty_book.xlsx')
    
    sheet_ranges = wb.get_sheet_by_name(name = 'range names')
    
    print sheet_ranges.cell('D18').value # should display D18
    

    Code is published under the MIT licence, so you can use it for whatever use you need, and I’d be very happy if  you drop me an email if  you use it 🙂

    If you don’t find it useful, spot a bug, or want to suggest an enhancement, you can do so by filling a ticket on the tracker.

    Features that will be added in the next version are listed here, so if you need something in this list, please be patient or send me a message to tell me to hurry 😉

  • openpyxl: simple writer done

    I’ve been very busy on openpyxl the last few days, and I managed to get a working writer for basic data types (strings, numerics).

    For the impatient, you can clone my bitbucket repository:

    hg clone https://ericgazoni@bitbucket.org/ericgazoni/openpyxl
    

    It’s still a work in progress, so expect some quirks here and there, and if that happens, please file a new issue here.

    If you like it, you can also drop a comment below or send me an email (see Contact page).

    Usage is pretty simple as you can see:

    from openpyxl.workbook import Workbook
    from openpyxl.writer.excel import ExcelWriter
    
    from openpyxl.cell import get_column_letter
    
    wb = Workbook()
    
    ew = ExcelWriter(workbook = wb)
    
    dest_filename = r'empty_book.xlsx'
    
    ws = wb.worksheets[0]
    
    ws.title = "range names"
    
    for col_idx in xrange(1, 40):
        col = get_column_letter(col_idx)
        for row in xrange(1, 600):
            ws.cell('%s%s'%(col, row)).value = '%s%s' % (col, row)
    
    ws = wb.create_sheet()
    
    ws.title = 'Pi'
    
    ws.cell('F5').value = 3.14
    
    ew.save(filename = dest_filename)
    
    

    Next features are:

    1. a working reader (so that I can read back files generated by the writer)
    2. dates support
    3. calculations
    4. formatting
  • Myth of the genius programmer

    This session held at Google I/O last year brings so many important ideas to become a better programmer that is should definitely be shown in CS classes (and in some IT shops :p).

    Thumbs up guys !

    [youtube=http://www.youtube.com/watch?v=0SARbwvhupQ]