Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Apache HSSF Problem

Reply
Thread Tools

Apache HSSF Problem

 
 
Audison.Athena@gmail.com
Guest
Posts: n/a
 
      01-09-2007
I ran into a peculiar problem when I use the apache poi library to
read an excel file. I think many people who has used this library
should have ran into this problem already and appreciate if anyone can
share his experience in solving this problem.
When I read some data from a pre-constructed excel file(the file was
created via office excel 2003, Chinese edition), I use the
getStringCellValue method to extract each cell from each row. Whenever
I extract some cell in which the content was made up by all digits,
this method may throw the runtime exception NumberFormatException.
However some other cells' contents also was made up of digits, this
method may pass.
I searched some topics related to this problem over the web. some
solutions said that every cell has a type, the HSSF cell is classified
as six type: CELL_TYPE_BLANK CELL_TYPE_BOOLEAN CELL_TYPE_ERROR
CELL_TYPE_FORMULA CELL_TYPE_NUMERIC CELL_TYPE_STRING
and through the insight of the source code of the HSSFCell class, it
seems for a numeric type cell, if you use the getStringCellValue, it
will deliberately throw NumberFormatException. Some suggested before
extract each cell value, first extract its type use getCellType method,
using if-then-else statement to code for each statement.
However, I think this doesn't touch the core of the problem. The
substantial problem is that why some cell constructed by all digits
will be deemed as a numeric type by hssf? if this is the case, if I
want to read the data as "0099", then read as a numeric value, I will
get "99", which is not the accepted case.
In office excel, each cell can set its cell style, for example, normal,
numeric, currency, date, text, etc. However when I change the failed
cell's type to text, and ran the program again, the problem still
exist, it seems the hssf cell's type has no relation to the excel
file's cell type determined when it was created in excel. what even
puzzled me is that when I changed the failed cell to some aother
numeric value, and save, and then change back, and then save again.
Then this time the Program pass this cell, and failed at the next cell.
So the substantial problem I'm urgent to know is that what determined
the hssf cell type, judging from the contents that made the cell value?
or judging from some factor as that was set when the cell was created
by office excel that each cell was bound to a specific type, or some
other factor. Because I know little about the excel file format, so the
problem seems to be buried too deep for me, anyone can help?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
poi hssf getCellStyle problem cosmo Java 1 01-18-2008 05:29 AM
HSSF, excel and "out of memory" tony lincoln Java 0 03-02-2004 08:24 AM
excel---HSSF---not enough memory? tony lincoln Java 0 03-01-2004 05:34 PM
HSSF Get formula value SolutionPlanet Java 0 01-01-2004 03:30 PM
HSSF and Excel Pivot Tables David W. Java 0 07-28-2003 10:02 PM



Advertisments