I am using the SS user model org.apache.poi.ss.usermodel.* to read an XLS file. One column is formatted as "General" in Excel 2007 and contains data which is a series of user defined codes which can be purely alphabetic 'mycode' or numeric '123'.

The problem comes with the numeric values. Here POI reads the values and sets the cell type to be CELL_TYPE_NUMERIC. This returns the value as a double. The trouble is the code '366.0' is not the same code as '366' so I wish to get the value 'as entered'. I appreciate that Excel may have decided to store the value internally as a double, and there is no way to get the value back 'as it appears'. Is this the case, or does POI have some access to a lower level value?

If I set the CellType before reading the Cell contents I can achieve the desired aim.

private String getGeneralCellValue(Cell cell)
    {
        if(cell != null)
        {
            cell.setCellType(Cell.CELL_TYPE_STRING);
            String generalValue = cell.getStringCellValue();
...

Having read throw a previous discussion "Reading numeric values as strings from a cell" it would seem that this is deprecated. Is this so?

Is there any way to achieve this goal without forcing users to format the column as text ("@")? If I use a formatter can I distinguish between a user entering "366" and "366.0"?

Thanks.
BTW Thanks generaly for the POI it certainly makes life a lot easier.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to