Hello all;
I am running into some more formula problems in reading my spreadsheet. Here is a very simple program that I am trying from the apache site but it throws this error:
*********************************************************************************
Exception in thread "main" java.lang.NullPointerException
at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.internalEvaluate(HSSFFormulaEvaluator.java:281) at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluate(HSSFFormulaEvaluator.java:181)
        at tradeshow.poiformulaevaluation.main(poiformulaevaluation.java:42)
*********************************************************************************
The code that I am using...
*********************************************************************************
public class poiformulaevaluation {

   public static void main(String[] args)

   {

       try
       {
       FileInputStream fis = new FileInputStream("c:/temp/test.xls");
       HSSFWorkbook wb = new HSSFWorkbook(fis);
       HSSFSheet sheet = wb.getSheetAt(0);
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);

//         suppose your formula is in B3
       CellReference cellReference = new CellReference("C3");
       HSSFRow row = sheet.getRow(cellReference.getRow());
       HSSFCell cell = row.getCell(cellReference.getCol());
       HSSFFormulaEvaluator.CellValue cellValue = evaluator.evaluate(cell);

       switch (cellValue.getCellType()) {
        case HSSFCell.CELL_TYPE_BOOLEAN:
System.out.println("BOOLEAN VALUE : " + cellValue.getBooleanValue());
                break;
        case HSSFCell.CELL_TYPE_NUMERIC:
System.out.println("NUMERIC VALUE : " + cellValue.getNumberValue());
                break;
        case HSSFCell.CELL_TYPE_STRING:
System.out.println("STRING VALUE : " + cellValue.getStringValue());
                break;
        case HSSFCell.CELL_TYPE_BLANK:
                break;
        case HSSFCell.CELL_TYPE_ERROR:
                break;

        // CELL_TYPE_FORMULA will never happen
        case HSSFCell.CELL_TYPE_FORMULA:
                break;
       }

       }

       catch(IOException ioex)
       {
          ioex.printStackTrace();
       }




   }
}
******************************************************************************
Spreadsheet data...
******************************************************************************
num1 num2 sum(=SUM(A2:B2)) <---formula included in the column"sum"
2                        4                   6
3                        5                   8
3                      69                   72
3                        5                   8
3                        4                   7
3                        5                   8
6                        4                   10
4                        1                   5
4                        8                   12
5                      89                   94
4                      26                   30
*******************************************************************************
I am using poi-scratchpad-3.0-alpha2-20060616.jar. Should I be using some other .jar file? Any help in resolving this problem would be much appreciated.

Thanks in advance,

Mike.

_________________________________________________________________
Got something to buy, sell or swap? Try Windows Live Expo ttp://clk.atdmt.com/MSN/go/msnnkwex0010000001msn/direct/01/?href=http://expo.live.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/

Reply via email to