5

I'd like to convert an excel spreadsheet to a component of c# code. To get it goin' I like to get all cells of a sheet containing fomulars into c# via interop. In the c# module I'd like to solve the defined fomulars with different values replacing the cell references in the fomular. Is there a framework where I can for example convert a "SUM($C3 : $C5)" from excel to a "var sum = c3 + c4 + c5;" or semilar formulars?

regards gordon

4 Answers 4

6

I think you are looking for an expression evaluator in C#.

Google found a few that I think you should look at:

You might also need implementations of all those built-in Excel functions. There's a library with all the financial functions re-implemented in F# by Luca Bolognese - find it on MSDN.

Sign up to request clarification or add additional context in comments.

Comments

1

More power than what you need, but with some luck only a thin interface wrapper is needed to pump data out of execl into formula engine:

FormulaEngine is a .NET assembly that enables you to add formula support to your application. It takes care of parsing and evaluating formulas, tracking their dependencies, and recalculating in natural order. The formula syntax and much of the engine's functionality are direct replicas of Excel ensuring a low learning curve for users.

Link: FormulaEngine


Update: I recently started a similar python library: pycel

Comments

1

Check out ActiveMesa X2C, which does precisely that. (Disclaimer: I'm the author of said product.)

2 Comments

Fixed the URL..
Thanks - updated link appears fine; deleted my earlier comment and removed my downvote.
0

Is this something you'll do repeatedly or just one time?

We're using www.spreadsheetgear.com to manipulate Excel spreadsheets from C# and it works wonderfully. Our needs are different, so you should study the API to see if it gives you access to the text of the forumulas, but I think it might.

No affiliation - just a satisfied customer.

2 Comments

Getting the formular out of the spreadsheet is not the problem. This is already accomplished via office-interop. The result is the fomular in string format. I want to replace references like "C22" with another value and then solve the formular without excel. Since I'm already in c# code I'd like to solve the formular there.
Oh I see it can evaluate calculations given to it. This might be a solution but since it's not free I think I could not use it. But it gets the solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.