Bug 40296

Summary: HSSFCell.setCellFormula throws ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
Product: POI Reporter: Peter Lachall <peterl>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 2.5-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Test Case

Description Peter Lachall 2006-08-22 17:41:00 UTC
The following program throws ClassCastException at line 22. Error message states
"org.apache.poi.hssf.record.BoolErrRecord cannot be cast to
org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate". Seems like there
may be a missing break near line 232 of HSSFCell. Thanks.

import java.io.*;
import org.apache.poi.hssf.usermodel.*;

public class FormulaTest {

  public static void main (String[] args) {

    try {
      FileOutputStream out = new FileOutputStream("FormulaTest.xls");

      HSSFWorkbook workBook = new HSSFWorkbook();
      HSSFSheet workSheet = workBook.createSheet("Sheet1");
      HSSFCell cell = null;
      HSSFRow row = null;

      row = workSheet.createRow(0);
      cell = row.createCell((short)0, HSSFCell.CELL_TYPE_NUMERIC);
      cell.setCellValue(1.0);
      cell = row.createCell((short)1, HSSFCell.CELL_TYPE_NUMERIC);
      cell.setCellValue(2.0);
      cell = row.createCell((short)2, HSSFCell.CELL_TYPE_FORMULA);
      cell.setCellFormula("SUM(A1:B1)");
      workBook.write(out);
      out.close();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }
}
Comment 1 Peter Lachall 2006-08-22 19:18:40 UTC
Created attachment 18742 [details]
Test Case
Comment 2 Avik Sengupta 2007-01-16 01:47:13 UTC
Works as of 12Jan2007, Testcase added. 
http://issues.apache.org/bugzilla/show_bug.cgi?id=41366