tags:

views:

1135

answers:

5

I've been given the task of connecting my code (fortran) with py (2.5), and generate a number of excel reports if possible. The first part went fine - and is done with, but now I'm working on the second.

What are my choices for making excel (2007 if possible) sheets from python ? In general, I would need to put some array values in them in a table (formatting doesn't matter), and draw a number of charts from those tables. Is there a way to do this automatically ? Some library ?

Anyone done something like this in the past ?

+2  A: 

I believe you have two options:

  1. Control Excel from Python (using pywin32, see this question). Requires Windows and Excel.
  2. Use the xlwt pure Python library.

I have not tried xlwt, I do not know if it handles charts.

codeape
+4  A: 

You're simplest approach is to use Python's csv library to create a simple CSV file. Excel imports these effortlessly.

Then you do Excel stuff to make charts out of the pages created from CSV sheets.

There are some recipes for controlling Excel from within Python. See http://code.activestate.com/recipes/528870/ for an example. The example has references to other projects.

Also, you can use pyExcelerator or xlwt to create a more complete Excel workbook.

S.Lott
Note: neither pyExcelerator nor xlwt do charts.
John Machin
+1  A: 

PyExcelerator has some quirks that you need to work around (atleast it did when I last used it), but it will do the job quite well.

I haven't tried xlwt, but as it's a fork of PyExcelerator, one might suspect that it has all the same features, and hopefully less quirks.

Epcylon
"Less quirks" or "fewer quirks"?
S.Lott
Not being a native english speaker I'm not sure I see the difference between the two?
Epcylon
+1  A: 

@S.Lott covered most of the bases. You might also consider generating an HTML <table>. Here's a sample I found with a quick search: Creating Excel Files with Python and Django

technomalogical
+1  A: 

There is a package on PyPi call xlutils which might help and there is this presentation from Chris Withers (lightning talk from last EuroPython I think) where you can see some example code with xlrd and xlwt. Looks easy ;-)

Hope that helps.

MrTopf