Apache POI : How to format numeric cell values

apache-poi

I am using Apache POI 3.9 for XLS/XLSX file processing.

In the XLS sheet, there is a column with numeric value like "3000053406".

When I read it with POI with..

cell.getNumericCellValue()

It gives me value like "3.00E+08". This create huge problem in my application.

How can I set the number formatting while reading data in Apcahe POI ?

There is a way that I know is to set the column as "text" type. But I want to know if there is any other way at Apache POI side while reading the data. OR can we format it by using simple java DecimalFormatter ?

Best Solution

This one comes up very often....

Picking one of my past answers to an almost identical question

What you want to do is use the DataFormatter class. You pass this a cell, and it does its best to return you a string containing what Excel would show you for that cell. If you pass it a string cell, you'll get the string back. If you pass it a numeric cell with formatting rules applied, it will format the number based on them and give you the string back.

For your case, I'd assume that the numeric cells have an integer formatting rule applied to them. If you ask DataFormatter to format those cells, it'll give you back a string with the integer string in it.

Related Question