2

I am using APACHE POI & Java for reading Excel sheet and create a file of my format. But its noticed that when a number string is read, the code saves it in number format. E.g.

12345677

becomes

1.2345E7

How to format it correctly?

Current code

            Vector cellStoreVector=(Vector)dataHolder.elementAt(0);
            for (int j=0; j < cellStoreVector.size();j++){
                HSSFCell myCell = (HSSFCell)cellStoreVector.elementAt(j);
                String stringCellValue = myCell.toString();
                bufferedWriter.write(stringCellValue + "|");
            }
Mobile Developer
  • 231
  • 2
  • 15
  • 1
    As mentioned by @Gagravarr, its better to use DataFormatter. For time being your issue may be solved. But the method I have mentioned may not be working for all other data formats. – Balu SKT Feb 26 '16 at 13:36
  • 1
    Yes, DataFormatter seems to better function than this. – Mobile Developer Feb 26 '16 at 13:36

1 Answers1

0

It happened to me also. Use below code while reading a cell to keep the format as string itself.

your_cell.setCellType(Cell.CELL_TYPE_STRING);

Hope this helps.

Similar question is asked here.

Community
  • 1
  • 1
Balu SKT
  • 549
  • 5
  • 22
  • 1
    Did you [try reading the Javadocs for that method](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Cell.html#setCellType%28int%29)? Only they are very clear that this isn't the right way to do it! – Gagravarr Feb 26 '16 at 13:13
  • 2
    true. But this helped me resolving my issue. The Javadocs clearly stops us from using this method. – Balu SKT Feb 26 '16 at 13:31