Just for the sake of completness - and to correct an errorneous statement I made yesterday - I have been playing around with the code a little more. This is the minimu that will work successfully it seems;
double value = cell.getNumericCellValue(); String strValue = decFormat.format(value); value = Double.parseDouble(strValue); cell.setCellValue(value); cell.setCellStyle(style); This is just that piece of code that sits in the switch statement and will be executed when a numeric value is read from the worksheet cell. From this, you can see that it is possible to set a style for a cell whose type Excel calls General. Interestingly, this is not possible from within the application itself which is quite surprising and led me to make that statement yesterday which I must now acknowledge was incorrect. In addition, I tried another, possibly quicker as fewer onjects are concerned, way of rounding the value; it looked like this double value = cell.getNumericCellValue(); value = value * 10; value = Math.round(value); value = value / 10; but it did not work quite as well as the previous piece of code. If the cell held a value of 1.04 for example, I am guessing that you would want to see it replaced with the value 1.0 but this did not happen using the 'alternative' rounding code above. Instead, it write the value 1 to the cell. Yours Mark B -- 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-tp3404980p3407830.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]
