我正在将复杂 Excel 工作表中包含的功能转换为 ASP.Net 项目。在此我需要使用 VB.NET 或 c# 来解析/处理 excel 之类的公式。
我有一个显示会计数字的网格状结构,允许用户在所需的单元格中预先配置公式。
示例:- 在我的数据网格 Cell[2][1] 中,我应该能够配置
公式 = Sum(单元格[1][1] + 单元格[1][2])。
有没有办法从 vb.net/c# 解析/处理 excel 公式?
最佳答案
你可以解决 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");
关于c# - 如何解析 excel 公式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38306556/