Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to write numeric cells in Jakarta POI/HSSF?

807569Jun 25 2006 — edited Jun 25 2006
This might sound like a newbie question, but it's weird. I've tried everything I could come up with, it seems like HSSF simply ignores the format and makes a "general" or "string" cell nonetheless.

This means users get a green arrow for each cell stating an "error" called "Number stored as text"...

Here are some (relevant) excerpts from my code...
HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet();
		
HSSFCellStyle cellStyle = book.createCellStyle();
cellStyle.setDataFormat( book.createDataFormat().getFormat("0.00") );
(...)
HSSFRow row = sheet.createRow( y );
(...)
HSSFCell cell = row.createCell( x );
(...)
cell.setCellType( HSSFCell.CELL_TYPE_STRING );
cell.setCellStyle( cellStyle );
cell.setCellValue( Double.parseDouble( orgRow.get( x ) ) );
I have tried commenting the setCellType() and setCellStyle() methods, but that doesn't seem to do anything.

The rest of the code is for-loops, etc. Also, lots of System.err.println(...) of course, to figure out what it's doing.

For example, I've tested using cell.getCellType() in a System.err.println(), but that agrees that the cell is indeed Numeric. However, Excel still gives the error.

I'm using POI release 2.5.1 (the current release), the latest Java+netBeans and Excel 2003.

If anyone could shed some light on this, I'd very much appreciate it.

Frederik Duijn
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2006
Added on Jun 25 2006
1 comment
361 views