I am using ClosedXML 0.76.0 to build my application, which handles Excel files.
At one moment, I populate an Excel file with formulas. So far, so good.
The user then gets this file and fills in values concerning the business.
At this moment, I read calculated values and populate another larger Excel file.
The problem is that when I try reading cells with fomulas, ClosedXML throws "Identifier Expected" exception.
My code is just as follows:
```
1 string formula = row.Cell(i).FormulaA1;
2 object result = workbook.Evaluate(formula);
3 sum += Convert.ToDecimal(result, CultureInfo.InvariantCulture);
```
The exception happens on line 2.
The formula is likely to be _'Indice'!D$5*'URCTS - 210'!G5_ or similar. There are single quotes delimiting worksheet names containing spaces.
Comments: The stack trace is as follows: ``` em ClosedXML.Excel.CalcEngine.CalcEngine.Throw(String msg) em ClosedXML.Excel.CalcEngine.CalcEngine.GetToken() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseExpression() em ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression) em ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression) em ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) em ClosedXML.Excel.XLWorkbook.Evaluate(String expression) em Siswebe.BLL.Business.PlanilhaGeral.GetDataTable(XLWorkbook wbEntrada) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 377 em Siswebe.BLL.Business.PlanilhaGeral.TransferirDadosProdutoQuimico(WorkbookPlanilhaGeralDTO dto, XLWorkbook wbPlanilhaGeral) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 307 em Siswebe.BLL.Business.PlanilhaGeral.TransferirDados(WorkbookPlanilhaGeralDTO dto, XLWorkbook wbPlanilhaGeral) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 410 em Siswebe.BLL.Business.PlanilhaGeral.GerarPlanilhaGeral(Stream outputStream) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 242 em Siswebe.GestaoAPE.EnviarPlanilhaGeral() na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe\GestaoAPE.aspx.cs:linha 356 em Siswebe.GestaoAPE.btnDownloadGeral_Click(Object sender, EventArgs e) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe\GestaoAPE.aspx.cs:linha 493 em System.Web.UI.WebControls.Button.OnClick(EventArgs e) em System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) em System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) em System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) em System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) em System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ``` I tried changing line 2 above by simply ``` 2 object result = row.Cell(i).Value; ``` but the exception thrown is the same.
At one moment, I populate an Excel file with formulas. So far, so good.
The user then gets this file and fills in values concerning the business.
At this moment, I read calculated values and populate another larger Excel file.
The problem is that when I try reading cells with fomulas, ClosedXML throws "Identifier Expected" exception.
My code is just as follows:
```
1 string formula = row.Cell(i).FormulaA1;
2 object result = workbook.Evaluate(formula);
3 sum += Convert.ToDecimal(result, CultureInfo.InvariantCulture);
```
The exception happens on line 2.
The formula is likely to be _'Indice'!D$5*'URCTS - 210'!G5_ or similar. There are single quotes delimiting worksheet names containing spaces.
Comments: The stack trace is as follows: ``` em ClosedXML.Excel.CalcEngine.CalcEngine.Throw(String msg) em ClosedXML.Excel.CalcEngine.CalcEngine.GetToken() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare() em ClosedXML.Excel.CalcEngine.CalcEngine.ParseExpression() em ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression) em ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression) em ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression) em ClosedXML.Excel.XLWorkbook.Evaluate(String expression) em Siswebe.BLL.Business.PlanilhaGeral.GetDataTable(XLWorkbook wbEntrada) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 377 em Siswebe.BLL.Business.PlanilhaGeral.TransferirDadosProdutoQuimico(WorkbookPlanilhaGeralDTO dto, XLWorkbook wbPlanilhaGeral) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 307 em Siswebe.BLL.Business.PlanilhaGeral.TransferirDados(WorkbookPlanilhaGeralDTO dto, XLWorkbook wbPlanilhaGeral) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 410 em Siswebe.BLL.Business.PlanilhaGeral.GerarPlanilhaGeral(Stream outputStream) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe.BLL\Business\PlanilhaGeral.cs:linha 242 em Siswebe.GestaoAPE.EnviarPlanilhaGeral() na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe\GestaoAPE.aspx.cs:linha 356 em Siswebe.GestaoAPE.btnDownloadGeral_Click(Object sender, EventArgs e) na d:\Projetos\ProcessosSDI\vBase\Siswebe\Siswebe\GestaoAPE.aspx.cs:linha 493 em System.Web.UI.WebControls.Button.OnClick(EventArgs e) em System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) em System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) em System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) em System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) em System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) ``` I tried changing line 2 above by simply ``` 2 object result = row.Cell(i).Value; ``` but the exception thrown is the same.