14,920,659 members
See more:
Hi,

This is the improved version of my requirement.
I am having more Excel formulae stored in DB. So retrieving them I need to calculate the values by writing logic for that formula dynamically.
For Ex:
Excel Formula :
VB
```IF(A>B,1,2)
A=4 and B=5```

Code to be generated:
VB
```IF(A>B)
{
Value = 1
}
Else
{
Value = 2
}```

Hi,

I would like to get the coding for Evaluation of Excel formula in run time using C#. Could anyone help me to attain this target.

Thanks
Mathi
Posted
Updated 24-Apr-13 21:54pm
v3
Maciej Los 4-Apr-13 3:18am

Please, be more specific and provide more details.
What have you done till now?
Mathi2code 5-Apr-13 2:01am

Hi Maciej,

Thanks for the response. I have updated my requirement clearly. Please help me in this. Also have an example like that you can have 'n' Excel formulae like Roundup,IsBlank,recursive IF condition etc.

With Regards,
Mathi

## Solution 1

Hi,

Automate Microsoft Excel from Microsoft Visual C#.NET

You will need to automate excel usage from c#.
Kenneth Haugland 4-Apr-13 7:12am

5'ed.

## Solution 2

http://support.microsoft.com/kb/302084

You gennerally get the formula of the cell by `Cell.Value` and you get the underlying formula by writing `Cell.Formula`.
Mathi2code 5-Apr-13 1:59am

Hi Jose and Kenneth,

Thanks for the response. I think my Question was not clear earlier, now I have updated it in a clear Please help me in this.

With Regards,
Mathi
Kenneth Haugland 25-Apr-13 3:58am

With the information you provided here, you might just load a new excel sheet and make it do the calculations. That would be te easiest, using Interop.
Mathi2code 29-Apr-13 1:29am

Interop is easiest way but for that we require the excel to installed in our local machine. Also Each and every time when a user uses a session of excel will be opened which is another drawback which I consider. Hence I go for the link which I have added to this post. Please check that.

Regards,
Mathi

## Solution 3

A Tiny Expression Evaluator[^]

Thanks & Regards,
Mathi

## Solution 4

A Tiny Expression Evaluator[^]A Tiny Expression Evaluator[^]
v2