Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read exact cell content of excel file in apache POI

when I read a content of cell for e.g. if it is in date format it casts into some another value like 12/31/2099 -> 46052 and $50.00 -> 50 and 50.00% -> 0.5.

But what I want is to get the exact string value for every cell.

My Code is like this:

cell.setCellType(Cell.CELL_TYPE_STRING);
String str = cell.getStringCellValue();
like image 300
yonjans Avatar asked Dec 22 '25 12:12

yonjans


1 Answers

No need for explicit formatting, Apache POI provides for DataFormatter class as utility to leverage the format of the content as it appears on the excel. You can choose custom formats too, a simple example would be (cell is reference to your XSSFCell object):

System.out.println(new DataFormatter().formatCellValue(cell));

Excel sheet looks like:

enter image description here

Using DataFormatter (sop statement above) prints:

50%
$ 1,200
12/21/14

Where your normal formatting would print:

0.5
1200.0
21-Dec-2014
like image 180
StoopidDonut Avatar answered Dec 24 '25 02:12

StoopidDonut



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!