c# - 如何解析 excel 公式?

标签 c# vb.net excel

我正在将复杂 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/

相关文章:

c# - 如果 < 10,则在数字前加 0

c# - 使用 Auth0 进行 Azure AD 身份验证

C# Protractor - 在另一个元素中查找元素

C# 与 VB.Net - 隐式转换

javascript - 在同一页面上出现两次的用户控件需要 JavaScript 的唯一 div id

c# - 从 C# 中的文本文件中读取矩阵

VB.NET 和 LINQ 查询字典

vba - 如何使用For循环替换偏移单元格

vba - 如何修复 "not responding"?

java - 如何使用 Apache POI 读取具有日期的 Excel 单元格?