简体   繁体   English

如何解析Excel公式?

[英]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.

相关问题 openxml sdk excel如何解析和计算公式 - openxml sdk excel how to parse and calculate formula 如何使用“平均”公式限制Excel单元格中的小数位数? - How can I restrict the decimal count in an Excel cell with an “Average” formula? 如何使用C#访问Excel工作表中的公式? - how can I access the formula in an excel sheet with c#? 如何使用 Excel Interop 检索与基于引用另一个 Excel 工作表的公式的 Excel 单元格关联的值? - How can I retrieve the value associated with an Excel Cell that is based on a formula referencing another Excel Sheet using Excel Interop? 我如何在C#for Excel中使用函数替换为公式 - How I can use in C# for Excel, the function Replace with the function Formula 正则表达式从Excel公式解析URL - Regex to parse URL from an excel formula 如何在公式中使用SQL值 - How can I use a SQL value in a formula 如何在 LINQ 中执行此公式? - How can I do this formula in LINQ? 如何防止绿色警告三角形显示在公式绑定的单元格中(C#Excel Interop)? - How can I prevent the green warning triangle from displaying in a formula-bound cell (C# Excel Interop)? 如何使用以下公式确定变量的值? - How can I use the following formula to determine the value of a variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM