Is it still looking good?

What is odd, is that like you I've seen that the General and @ formats don't
work correctly, but I experience different incorrect behaviour than you do
for your 0.0005 example. For General format, I get '0.'  and for '@' format
I get 5.0E-4. This is with poi 3.7 jars. I'm wondering if there is also
something else going on. This is my sample code and output. Can you see
please what I'm doing differently in my code than in yours?


Sample code:

InputStream is = new FileInputStream("Workbook with 0.0005 in cell A1.xls");
    
XSSFWorkbook wb = new XSSFWorkbook(is);
XSSFSheet sheet = wb.getSheet("Sheet1");
XSSFRow row = sheet.getRow(0);
XSSFCell cell = row.getCell(0);

System.out.println(cell.getNumericCellValue());
                        
CellFormat cellFormat1 = CellFormat.getInstance("General");
String formattedData1 = cellFormat1.apply(cell).text;

System.out.println("'General' format: " + formattedData1);

CellFormat cellFormat2 = CellFormat.getInstance("@");
String formattedData2 = cellFormat2.apply(cell).text;

System.out.println("'@' format: " + formattedData2);
        
is.close();


Output:

5.0E-4
'General' format: 0.     <-- you see 5.0E-4 for 'General' format
'@' format: 5.0E-4

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Reading-cell-values-that-have-a-custom-format-tp5486315p5506619.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]

Reply via email to