Apache HSSF Problem

Discussion in 'Java' started by Audison.Athena@gmail.com, Jan 9, 2007.

  1. Guest

    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?
     
    , Jan 9, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David W.

    HSSF and Excel Pivot Tables

    David W., Jul 28, 2003, in forum: Java
    Replies:
    0
    Views:
    2,123
    David W.
    Jul 28, 2003
  2. SolutionPlanet

    HSSF Get formula value

    SolutionPlanet, Jan 1, 2004, in forum: Java
    Replies:
    0
    Views:
    580
    SolutionPlanet
    Jan 1, 2004
  3. tony lincoln

    excel---HSSF---not enough memory?

    tony lincoln, Mar 1, 2004, in forum: Java
    Replies:
    0
    Views:
    922
    tony lincoln
    Mar 1, 2004
  4. tony lincoln

    HSSF, excel and "out of memory"

    tony lincoln, Mar 2, 2004, in forum: Java
    Replies:
    0
    Views:
    1,517
    tony lincoln
    Mar 2, 2004
  5. cosmo
    Replies:
    1
    Views:
    1,805
    salma
    Jan 18, 2008
Loading...

Share This Page