Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有什么好方法可以将“xlSum”、“xlAverage”和“xlCount”等字符串转换为它们在 Microsoft.Office.Interop.Excel.XlConsolidationFunction 下的值?
我想反射会很慢(如果可能的话)。这些常数值大约有 10 个。如果可能的话,我试图避免使用大的 switch 语句。
这是一个枚举,所以你应该能够使用
using Microsoft.Office.Interop.Excel; XlConslidationFunction func = (XlConsolidationFunction) Enum.Parse( typeof(XlConsolidationFunction), stringVal );
您可以始终使用 aDictionary<string, ...>并在应用程序启动时填充一次,而不是 switch
Dictionary<string, ...>