I working with Excel support for a software which uses both xls and xlsx file formats.

I am writing code which reads an excel spreadsheet and shows the spreadsheet in a JTable. The software calculates some new values to the table and put the calculated values to the table. When I am setting calculated values to the table, the style of cells is not read correctly. I have to set the column style always after setting the value. Is there way to set the value with the style without using my (getColumnStyle-setColumnStyle) hack?

private void setRowValue(Row row, String[] columns, String columnName, Object value, Sheet sheet) {
int index = indexOf(columns, columnName);
if (index >= 0) {
Cell cell = row.getCell(index);
if (cell == null) {
cell = row.createCell(index);
setCellValue(value != null ? value : "n/a", cell);
CellStyle columnStyle = sheet.getColumnStyle(index);
if (columnStyle != null) {

Any help is welcome!