ClosedXML System.Exception:语法错误

时间:2014-11-24 07:40:26

标签: c# asp.net excel closedxml

我正在使用ClosedXML从用户提供的输入中计算Excel工作表中的值,并且我在包含以下公式的单元格上出现错误

  

如果(C2 = 1,VLOOKUP(D7,A15:D28,4),(IF(C2 = 2,VLOOKUP(D7,A33:D46,4),VLOOKUP(D7,F15:I28,4))) )

在线:

lblResult.Text = worksheet.Cell("D8").Value;

你能帮我找到这里出了什么问题吗?

提前致谢

以下是堆栈跟踪 堆栈跟踪:

[Exception: Syntax error.]
   ClosedXML.Excel.CalcEngine.CalcEngine.GetParameters() +223
   ClosedXML.Excel.CalcEngine.CalcEngine.ParseAtom() +141
   ClosedXML.Excel.CalcEngine.CalcEngine.ParseUnary() +77
   ClosedXML.Excel.CalcEngine.CalcEngine.ParsePower() +16
   ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv() +16
   ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub() +16
   ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare() +16
   ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression) +67
   ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression) +140
   ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) +27
   ClosedXML.Excel.XLCell.get_Value() +411
   TestExcel.btnResult_Click(Object sender, EventArgs e) in f:\Projects\Generation Circuit\gencricuit\GenerationCircuit\TestExcel.aspx.cs:30
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628026
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

2 个答案:

答案 0 :(得分:1)

ClosedXML不支持VLOOKUP函数。

请参阅documentation以获取支持的功能列表。

答案 1 :(得分:0)

您可以使用worksheet.Cell(“ D8”)。CachedValue 它将根据计算结果显示在单元格中的值