Bug 44861

Summary: ClassCastException in evaluateFormulaCell
Product: POI Reporter: Emmanuel F <e.fougeras>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: critical    
Priority: P1    
Version: 3.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Attachments: Testcase

Description Emmanuel F 2008-04-23 09:11:12 UTC
Tested with poi-3.0.2-FINAL

java.lang.ClassCastException: org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate cannot be cast to org.apache.poi.hssf.record.LabelSSTRecord
        at org.apache.poi.hssf.usermodel.HSSFCell.setCellValue(HSSFCell.java:625)
        at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluateFormulaCell(HSSFFormulaEvaluator.java:253)


My code :

private final void updateAllFormulas(final HSSFWorkbook parWorkbook) {
    final int locNumberOfSheets = parWorkbook.getNumberOfSheets();
    for (int locSheetNum = 0; locSheetNum < locNumberOfSheets; locSheetNum++) {
      final HSSFSheet locSheet = parWorkbook.getSheetAt(locSheetNum);
      final HSSFFormulaEvaluator locEvaluator = new HSSFFormulaEvaluator(locSheet, parWorkbook);

      for (final Iterator locSheetIter = locSheet.rowIterator(); locSheetIter.hasNext();) {
        final HSSFRow locRow = (HSSFRow) locSheetIter.next();
        locEvaluator.setCurrentRow(locRow);

        for (final Iterator locCellIter = locRow.cellIterator(); locCellIter.hasNext();) {
          final HSSFCell locCell = (HSSFCell) locCellIter.next();
          if (locCell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
            locEvaluator.evaluateFormulaCell(locCell);            
          }
        }
      }
    }
  }
Comment 1 Nick Burch 2008-04-27 11:00:29 UTC
Please upload the problem excel file, so we can take a look and see what POI is doing wrong (the stacktrace shows something happening that ought not to)
Comment 2 Emmanuel F 2008-04-28 10:43:02 UTC
Created attachment 21870 [details]
Testcase
Comment 3 Emmanuel F 2008-04-28 10:44:43 UTC
The problem excel file is in attachments.
Comment 4 Nick Burch 2008-04-28 10:53:16 UTC
Just tried on svn trunk, and works just fine, no exception. Test added to svn verifies this

Please retry with 3.1 beta 1 (should be on mirrors shortly) or a svn nightly build. 
Comment 5 Josh Micich 2008-04-28 12:00:17 UTC
The stack trace seems to be the same as that from bug 44606

*** This bug has been marked as a duplicate of bug 44606 ***