Search code examples
javaexcelformatapache-poicell

Change cell format (Length?) in Java Poi (Excel)


I have been searching for a way to do this but only found a few methods to resize columns, and wasn´t enough.

It´s simple:

When I´m writting into an excel file, I get to a point where numbers get higher than 10.000.000, and the format changes, example:

row 11: 9.800.000

row 12: 9.900.000

row 13: 1.0E7

row 14: 1.01E7

How can I prevent this from happening? I need the whole number, as I later access this information again from my code.

(I can´t edit excel manually, as I create it dinamically, I guess (and hope) there is a variable in some Java POI class that I can assign a value for this to change?)

Thank you all.


Solution

  • The easiest way would probably be to just convert the value when you extract it from the excel file.

    BigDecimal bigNumber = new BigDecimal(cell.getNumericCellValue());
    //Use bigNumber when doing the calculations