0
votes

I am using Apache POI to store data in excel sheet. I can store data like "50%" in the cell. Excel also shows up, but it show error like "Number stored as String".

If i click that message and click "convert number to String". It shows perfectly.

How to store it without errror using POI

1

1 Answers

3
votes

This code will work

Create a style with a format of %

and set the value as a number (double) and not with %

setCellValue(double value)

The output will be 50%

CellStyle style = workBook.createCellStyle();
style.setDataFormat(workBook.createDataFormat().getFormat("0%"));
cell.setCellStyle(style);
cell.setCellValue(0.50); // set value as number