Java – Setting Excel cell value in Numeric format using POI


I want to store numeric data in excel sheet.
The numeric data is represented by String type in my java code.
Is it possible to set it as numeric without casting it?

I've tried the following code, but it wasn't converted to numeric type (I get a warning in excel saying that number is stored as text…)

HSSFCell dCell =...

Best Solution

You have to provide the value as a double. As the doc says:


public void setCellValue(double value)

set a numeric value for the cell


value - the numeric value to set this cell to. For formulas we'll set the precalculated value, for numerics we'll set its value. For other types we will change the cell to a numeric cell and set its value.

So, it should be

dCell.setCellValue(new Double("123"));


dCell.setCellValue(123);  //Remember, the way you did was, you actually passed a string (no quotes)