I have an Excel spreadsheet with calculations I would like to use in a Django web application. I do not need to present the spreadsheet as it appears in Excel. I only want to use the formulae embedded in it. What is the best way to do this?
-
Do you want to extract the formulas or do you just want the data? – Jim Mitchener Dec 10 '09 at 18:41
-
I just want to use the spreasheet as a calculation engine. – Dec 10 '09 at 18:44
-
re-tagged to include python in hopes that some python jedi that has done some excel spelunking would comment... – cethegeek Dec 10 '09 at 20:43
-
1Are the formulas entered by users? If not, what calculations do you want to do in Excel that can't be easily expressed in Python? – John Machin Dec 10 '09 at 22:35
-
All the formulae *could* be expressed in python. Long term that may be where we need to go. For now, everything is expressed as complex excel spreadsheets. Also, if we rewrite in python, the domain experts lose the ability to modify their formulae. – Dec 11 '09 at 15:34
4 Answers
You can control Excel with Python via COM. See this thread: Driving Excel from Python in Windows
It might be a challenge to get this to work reliably as part of a Django app.

- 1
- 1

- 28,981
- 10
- 72
- 75
-
This is the direction we're going for now and reliability is proving elusive. Hopefully we sort it out soon. – Feb 04 '10 at 17:58
In addition to the COM solution, xlrd is cross-platform. That might be more suitable, since I believe Linux is still the most common deployment environment for django. It's also a lighter-weight solution than pyUno.

- 13,915
- 5
- 45
- 60
I think the only thing you can do is use some python/excel mechanism (the only one I could find was this: http://www.python-excel.org/; the tutorial makes me think it might be doable) to read and write from an excel spreadsheet.
You would write to certain cells that would be used by the spreadsheet formulas and then read the results from the formulas from other cells.
Django per-se has nothing to help you with this.
I'll retag your question to include python so that, maybe, someone with Python-excel experience can comment...

- 6,286
- 35
- 42
-
That leaves the issue of how to get the excel runtime working in a hosted situation(?) – Dec 10 '09 at 20:48
-
Have no clue - hence the retagging and hoping for a python person with experience doing this thing... – cethegeek Dec 10 '09 at 21:17
-
None of the software at python-excel.org will evaluate Excel formulas. To do that you need an Excel process. In a NON-hosted environment, this can be done but it's painful. – John Machin Dec 10 '09 at 23:10
You need to use Excel to calculate the results? I mean, maybe you could run the Excel sheet from OpenOffice and use a pyUNO macro, which is somehow "native" python.
A different approach will be to create a macro to generate some more friendly code to python, if you want Excel to perform the calculation is easy you end up with a very slow process.

- 6,283
- 6
- 33
- 46