There is nothing that you can do about that I am afraid. Setting the cell
explcitily to the numeric type in code has to be done so that the formatting
object can be applied to it successfully; it is a slight of hand or trick if
you will to force the formatting we want on the cell. Excel will still
interpret that cell as a 'Genral' type cell however when the workbook is
opened and viewed by the user and there is no way I know of to prevent it
from doing so after the fact. The reason for this is quite simple really.
POI does not parse every part of the Excel file's record structures and
preserves unchanged those sections it does not. I suspect that somewhere in
one of these darker recesses of the file is a flag or setting that
determines Excel will still treat the cell as being General rather than
numeric.
The best course of action would be to ensure that the cells type is set
appropriately when the workbook is created in the first place but I do not
know if you have any control over that part of the process.
Yours
Mark B
PS. I do not know if this will work - I suspect it will not - but you could
try recreating the cell in code rather than simply modifying the existing
cell. This mean knowing the row and column indexes of the cell - easy enough
as you already have a cell object in hand. So;
HSSFRow row = sheet.getRow(rowIndex);
HSSFCell cell = row.getCell(cellIndex);
if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
double cellValue = cell.getNumericCellValue();
cell = row.createCell(cellIndex);
cell.setCellValue(cellValue);
cell.setCellStyle(oneDecPlaceStyle);
}
That may work but I cannot promise that it will.
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Round-to-one-Decimal-place-not-happenning-using-style-setDataFormat-format-getFormat-0-0-tp3404980p3413620.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]