Solved

Evaluating Excel formulae (formulas if you prefer)

Posted on 2004-10-18
3
436 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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