This project has moved. For the latest updates, please go here.

Identifier Expected

May 16, 2013 at 7:14 AM
Edited May 16, 2013 at 7:15 AM

I am trying to copy information from one area of a ClosedXML sheet to another. I have the following setup:

Sheet1 is just data - as extracted from sql server (using ClosedXML - getting this happening was awesome; thank you MDeLeon).

On Sheet2 are a number of "='Sheet1'!<CellRef>" formulas (where <CellRef> is the A1 style reference for the cell).

I am trying to copy the information in those cells Sheet2 cells to a different range on Sheet2 using the following:
double sourceValue = ws.Cell("B12").GetDouble();
ws.Cell("B32").Value = sourceValue;
According to my understanding of the 'Evaluating a Formula' functionality, this should work, and give me the value of the cell (as a double). Please correct me if I have got this wrong.

However I am getting an 'Identifier Expected' exception on the double sourceValue = ... line with the following stacktrace:
   at ClosedXML.Excel.CalcEngine.CalcEngine.Throw(String msg)
   at ClosedXML.Excel.CalcEngine.CalcEngine.GetToken()
   at ClosedXML.Excel.CalcEngine.CalcEngine.ParseExpression()
   at ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression)
   at ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression)
   at ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
   at ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue(IXLCell cell)
   at ClosedXML.Excel.CalcEngine.CellRangeReference.GetValue()
   at ClosedXML.Excel.CalcEngine.XObjectExpression.Evaluate()
   at ClosedXML.Excel.CalcEngine.Expression.op_Implicit(Expression x)
   at ClosedXML.Excel.CalcEngine.BinaryExpression.Evaluate()
   at ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
   at ClosedXML.Excel.XLWorksheet.Evaluate(String expression)
   at ClosedXML.Excel.XLCell.get_Value()
   at ClosedXML.Excel.XLCell.TryGetValue[T](T& value)
   at ClosedXML.Excel.XLCell.GetValue[T]()
   at ClosedXML.Excel.XLCell.GetDouble()
   at LGFinance.ViewModel.MainViewModel.InsertExpenditureWorkings(IXLWorksheet sheet, Int32 startRow)
What have I done wrong? :-)
May 20, 2013 at 8:56 PM
The following does work:

namespace ClosedXML_Issues
class _443852
    public void Test()
        string targetFile = this.ToString() + ".xlsx";

        // Create workbook
        XLWorkbook wb = new XLWorkbook();

        // Sheet1 is just data - as extracted from sql server 
        IXLWorksheet ws1 = wb.Worksheets.Add("sheet1");
        ws1.Cell("A6").Value = 3.14159;  // everybody like pi

        // On Sheet2 are a number of "='Sheet1'!<CellRef>" formulas (where <CellRef> is the A1 style reference for the cell)
        IXLWorksheet ws2 = wb.Worksheets.Add("sheet2");
        ws2.Cell("B12").FormulaA1 = @"=sheet1!A6";

        // copy the information in sheet2 to a different range on Sheet2
        double sourceValue = ws2.Cell("B12").GetDouble();
        ws2.Cell("B32").Value = sourceValue;


The above generates a value in two cells in sheet2. Perhaps the single quotes around sheet1 is your issue??
  • MJH