I need to display a value in an excel cell formatted like a percentage, e.g. like 12.3%
.
By default the value is displayed as Text, but I need to display it as a number.
What is the appropriate method to achieve this?
You need to:
Something like:
cell.setCellValue(0.123); // set value as number
CellStyle style = workbook.createCellStyle();
style.setDataFormat(workbook.createDataFormat().getFormat("0.000%"));
cell.setCellStyle(style);
Take a look at user defined formats section of POI quick guide for more details. You may also want to go through the examples which show how to use different POI capabilities.