parsing an Excel formula with the re module

John Posner jjposner at optimum.net
Tue Jan 5 14:04:05 EST 2010


On Tue, 05 Jan 2010 13:12:00 -0500, vsoler <vicente.soler at gmail.com> wrote:

> Hello,
>
> I am acessing an Excel file by means of Win 32 COM technology.
> For a given cell, I am able to read its formula. I want to make a map
> of how cells reference one another, how different sheets reference one
> another, how workbooks reference one another, etc.
>
> Hence, I need to parse Excel formulas. Can I do it by means only of re
> (regular expressions)?
>
> I know that for simple formulas such as "=3*A7+5" it is indeed
> possible. What about complex for formulas that include functions,
> sheet names and possibly other *.xls files?
>
> For example    "=Book1!A5+8" should be parsed into ["=","Book1", "!",
> "A5","+","8"]
>
> Can anybody help? Any suggestions?

It seems like you want to recreate data structures that Excel, itself,  
must maintain in order to recalculate cells in the correct order. As long  
as you're using COM, you might be able to tap into those data structures.  
My 15-year-old (!) "Using Excel Visual Basic for Applications" book wasn't  
any help. :-( After a short Google session, I came up with one possible  
lead: http://www.decisionmodels.com/

Good luck!
John



More information about the Python-list mailing list