Can't retrieve value of a computed cell using JExcelAPI
<p>This is my first post, please bear with me.  I'm trying to do something simple:  look at the value of a spreadsheet cell that contains a formula.  Nothing seems to work, instead of the correct answer (579) , I get "4".  (output below).  This program creates a simple spreadsheet with numbers in A1 and A2, and the sum in A3.  </p>

<pre><code>   import java.io.*;
   import jxl.*;
   import jxl.Workbook;
   import jxl.biff.FormulaData;
   import jxl.biff.formula.FormulaException;
   import jxl.write.Number;
   import jxl.write.*;
   import jxl.write.Formula;
   import jxl.read.biff.CellValue;

   public class ReadCell {

     public static void main(String[] args) throws IOException,
                                     jxl.read.biff.BiffException,
                                     WriteException, FormulaException
     {
         String filename = "readcell.xls";
         WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
         WritableSheet ws = workbook.createSheet("Sheet1", 0);

         Number n = new Number(0,0,123);   // 123 in A1
         ws.addCell(n);
         n = new Number(0,1,456);          // 456 in A2
         ws.addCell(n);
         Formula f = new Formula(0,2, "A1+A2");  // formula in A3, yields 579
         ws.addCell(f);

         workbook.write();
         workbook.close();   

  //now try to retrieve the sum of A1 + A2, which is in A3 (value should be 579)
  Workbook wb = Workbook.getWorkbook( new File (filename));
  Sheet sheet = wb.getSheet(0);
  Cell cell = sheet.getCell("A3");

  System.out.println("\n\nCell A3 contents = " + cell.getContents());

  //that didn't work, maybe try it by casting to a NumberCell?
  NumberCell numbercell = (NumberCell)cell;
  System.out.println("NumberCell value = " + numbercell.getValue());
  System.out.println("NumberCell contents = " + numbercell.getContents());

  //that didn't work, maybe try it by casting to a FormulaCell?
  FormulaCell fc = (FormulaCell)cell;
  System.out.println("FormulaCell contents = " + fc.getContents());
  System.out.println("FormulaCell formula = " + fc.getFormula());

  //that didn't work, maybe try to get contents by casting to FormulaData?
  FormulaData fd = (FormulaData)cell;
  System.out.println("FormulaData contents = " + fd.getContents());
  System.out.println("FormulaData type = " + fd.getType());

  //that didn't work, maybe try to get contents by casting to NumberFormulaCell?
  NumberFormulaCell nfc = (NumberFormulaCell)cell;
  System.out.println("NumberFormulaCell value = " + nfc.getValue());
  System.out.println("NumberFormulaCell contents = " + nfc.getContents());
  System.out.println("NumberFormulaCell formula = " + nfc.getFormula());

  //that didn't work, try to get contents by casting to CellValue?
  CellValue cv = (CellValue)cell;
  System.out.println("cellValue contents = " + cv.getContents());

  //Nothing works and these casts won't compile:
  //Number nnn = (Number)cell;
  //NumberFormulaRecord nfr = (NumberFormulaRecord)cell; 

  wb.close();
  }
}
</code></pre>

<p>Here is the output, the "4"s should be "579"s</p>

<p>Cell A3 contents = 4</p>

<p>NumberCell value = 4.0</p>

<p>NumberCell contents = 4</p>

<p>FormulaCell contents = 4</p>

<p>FormulaCell formula = A1+A2</p>

<p>FormulaData contents = 4</p>

<p>FormulaData type = Numerical Formula</p>

<p>NumberFormulaCell value = 4.0</p>

<p>NumberFormulaCell contents = 4</p>

<p>NumberFormulaCell formula = A1+A2</p>

<p>cellValue contents = 4</p>

<p>Thanks for any help you can provide!</p>