Bug 18444

Summary: Setting Formula in cell in POI Ver 1.8
Product: POI Reporter: Vikranth <vgujjar>
Component: HSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: Other   
OS: All   

Description Vikranth 2003-03-28 05:50:57 UTC
I tried to set formula in a cell using following three ways.

1. HSSFCell cell = sheet.createCell(1);
2. cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
3.  cell.setCellFormula("A2+B2");
Gives Error on line 2

1. HSSFCell cell = sheet.createCell(1,HSSFCell.CELL_TYPE_FORMULA);
2. cell.setCellFormula("A2+B2");
 This works but for only once i.e if I try setCellFormula again it gives a 
ClassCastException line 458 in HSSFCell.java()

1. HSSFCell cell = sheet.createCell(1);
2. cell.setCellFormula("A2+B2");
 This works perfectly
Comment 1 Toshiaki Kamoshida 2003-03-28 07:20:47 UTC
I am not developer:D,but I have an opinion about the problem.

When I tried to call HSSFCell#setCellType(CELL_TYPE_STRING) to a cell having 
a "number value" and I fouund it causes Exception.It is reasonable because 
number value is already existed.

HSSFCell has some metod to set value,setCellFormula(formulla string) and 
setCellValue(for each value types).and in thease methods,inner logic 
automatically changes cell's type to right value.

So I feel,the method HSSFCell#setCellType() is no need to open as public method.
The matter that the method is pubic, may make users confuse(as I did:D).The 
method should be "deprecated method".
Comment 2 Vikranth 2003-03-28 07:52:22 UTC
 I went throught the source code I find that setCellFormula(String formula) 
calls the setCellType(HSSFCell.CELL_TYPE_FORMULA) so, you are right because 
this method  setCellType(HSSFCell.CELL_TYPE_FORMULA) is being called twice 
hence throws exception.

Thanks for your reply..
Comment 3 Andy Oliver 2003-07-24 16:01:56 UTC
this looks like a conversation that should have been on the list and has
resolved itself.