[英]How can I parse an excel formula?
I am converting the functionalities incorporated in a complex excel sheet to an ASP.Net project. 我正在将复杂的excel工作表中包含的功能转换为ASP.Net项目。 In this I have a requirement to parse/process excel like formula using VB.NET or c#.
在这种情况下,我需要使用VB.NET或c#解析/处理类似于公式的Excel。
I have a grid like structure which displays accounting figures and the user is allowed to pre-configure formula in required cells. 我有一个类似网格的结构,可以显示会计数字,并且允许用户在所需的单元格中预先配置公式。
Example :- In my datagrid Cell[2][1], I should be able to configure 示例:-在我的datagrid Cell [2] [1]中,我应该能够进行配置
formula = Sum(Cell[1][1] + Cell[1][2]) . 公式= Sum(Cell [1] [1] + Cell [1] [2]) 。
Is there a way we can parse/process excel formula from vb.net/c# ? 有没有办法可以从vb.net/c#解析/处理excel公式?
You could work around FLEE library to evaluate C# like expressions 您可以解决FLEE库,以评估类似C#的表达式
// Create the calculation engine
CalculationEngine engine = new CalculationEngine();
ExpressionContext context = new ExpressionContext();
VariableCollection variables = context.Variables;
// Add some variables
variables.Add("x", 100);
variables.Add("y", 200);
// Add an expression to the calculation engine as "a"
engine.Add("a", "x * 2", context);
// Add an expression to the engine as "b"
engine.Add("b", "y + 100", context);
// Add an expression at "c" that uses the results of "a" and "b"
engine.Add("c", "a + b", context);
// Get the value of "c"
int result = engine.GetResult<int>("c");
// Update a variable on the "a" expression
variables["x"] = 200;
// Recalculate it
engine.Recalculate("a");
// Get the updated result
result = engine.GetResult<int>("c");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.