Bug 40296 - HSSFCell.setCellFormula throws ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
Summary: HSSFCell.setCellFormula throws ClassCastException if cell is created using HS...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-22 17:41 UTC by Peter Lachall
Modified: 2007-01-16 01:47 UTC (History)
0 users



Attachments
Test Case (862 bytes, text/plain)
2006-08-22 19:18 UTC, Peter Lachall
Details

Note You need to log in before you can comment on or make changes to this bug.
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