C# - Evaluate Excel Logical Formulas

2020-02-09 09:20发布

I have an Application that need to evaluate Excel Logical Formulas and I use Excel DLL to do this, but DLL isn't it very efficient.

.NET Framework (C#) has any Class that can make this Job?

An sample

I Provide this

=IF(AND(10>=-5;10<0);(-3,8*10+335);IF(AND(10>=0;10<5);(1,4*10+335);IF(AND(10>=5;10<14,4);(-1,2766*10+348,38);IF(AND(10>=14,4;10<25);(-1,5094*10+351,74);IF(AND(10>=25;10<=45);(-1,4*10+349);0)))))

And get this

335,614

Thanks

标签: c# .net excel
6条回答
SAY GOODBYE
2楼-- · 2020-02-09 09:45
别忘想泡老子
3楼-- · 2020-02-09 09:45

We use SpreadsheetGear to do this - but it does a whole lot more than just evaluating formulas, so might be overkill for you.

It does seem to be fast, and provides a quite easy to use .NET API, too.

查看更多
ら.Afraid
4楼-- · 2020-02-09 09:47

There are a couple of math expression parsers out there, e.g. lundin, but I'm not sure they'll parse an excel expression for you. Does it have to be excel?

查看更多
Juvenile、少年°
5楼-- · 2020-02-09 09:49

I used bcParser.NET is a mathematical expression parser library for the .NET platform. this utility from bestcode organisation and easy to use to calculate all type of formula. refer to this http://www.bestcode.com/html/math_parser_for_dot_net.html

查看更多
三岁会撩人
6楼-- · 2020-02-09 09:59

I am using ActiveXls and it's doing a great job. It's not a free component so you have to pay for it. I don't know if there are any good and free components out there, but I prefer to have support in case I need it :)

查看更多
何必那么认真
7楼-- · 2020-02-09 10:04

Yes, agreed, the Excel.Application.Evaluate method can be slow. It usually suits my needs, but it's not lightening fast.

I think the best source for evaluating Excel formulas without the Excel object mode is:

Some other related articles:

Hope this helps...

查看更多
登录 后发表回答