Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Evaluating Excel formulae (formulas if you prefer)

Posted on 2004-10-18
3
435 Views
Last Modified: 2010-04-05
Anyone know how to do this ?

Given an Excel formula like
=SUM(D4:H12,A14-B15*2,100-(A19+B19*2))
how can I parse it and evaluate it???

There are expression evaluators at
http://swiss.torry.net/expressions.htm
but none specifically mention Excel.

Is there some formal definition of the Excel formula language? If so, one might expect that something like Lex and Yacc could be used. But that is a bit too much heavy lifting for me.

What about tweaking one of the existing expression evaluators ? Anyone have experience/suggestions. And yes I do want to parse AND evaluate, because I want to be able to identify cells that have been referenced in formulae




 
0
Comment
Question by:Mutley2003
3 Comments
 
LVL 6

Assisted Solution

by:vadim_ti
vadim_ti earned 250 total points
ID: 12337373
i think you can try to use "Excel.Application" object

  FExcel := CreateOleObject('Excel.Application');

info below is from MSDN about "Excel.Application" object

Visual Studio Tools for the Microsoft Office System  

How to: Run Excel Calculations Programmatically
The Calculate method runs all calculations in the specified object. Use the method of the object that limits the calculation range to the smallest number of cells that you want to recalculate. The recalculation engine in Microsoft Office Excel 2003 is very fast, but if you can limit the number of cells involved, you can optimize the operation.

To run calculations in a range

Call the Calculate method of the specified range. The following example requires a range named "SomeNamedRange" in the worksheet:
' Visual Basic
ThisApplication.Range("SomeNamedRange").Calculate()

// C#
ThisApplication.get_Range("SomeNamedRange",Type.Missing).Calculate();
To run calculations in all open workbooks

Call the Calculate method of the Application object:
' Visual Basic
ThisApplication.Calculate()

// C#
ThisApplication.Calculate();
0
 
LVL 31

Accepted Solution

by:
moorhouselondon earned 250 total points
ID: 12341570
The attached link deals with the parsing half of the problem:-

http://www.mcs.vuw.ac.nz/~db/FishBrainWiki?Excel


0
 

Author Comment

by:Mutley2003
ID: 12344141
moorhouselondon --the fishbrain stuff is cool .. a good link, thanks.

vadim - not quite what I had in mind, but there are some good ideas there.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question