Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Technique - Getting Constant Values By String

Is there any good way to convert strings like "xlSum", "xlAverage", and "xlCount" into the value they have under Microsoft.Office.Interop.Excel.XlConsolidationFunction?

I guess reflection would be slow (if its possible). There are about 10 of these constant values. I was trying to avoid a large switch statement if possible.

like image 300
BuddyJoe Avatar asked Dec 18 '25 17:12

BuddyJoe


1 Answers

This is an enum so you should be able to use

using Microsoft.Office.Interop.Excel;

XlConslidationFunction func = (XlConsolidationFunction)
                               Enum.Parse( typeof(XlConsolidationFunction),
                                           stringVal );
like image 64
tvanfosson Avatar answered Dec 20 '25 07:12

tvanfosson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!