Issue reading in a cell from Excel with Apache POI
Posted
by
Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2012-06-01T20:55:50Z
Indexed on
2012/06/03
16:40 UTC
Read the original article
Hit count: 252
I am trying to use Apache POI to read in old (pre-2007 and XLS) Excel files. My program goes to the end of the rows and iterates back up until it finds something that's not either null or empty. Then it iterates back up a few times and grabs those cells. This program works just fine reading in XLSX and XLS files made in Office 2010.
I get the following error message:
Exception in thread "main" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at the line:
num = Double.parseDouble(str);
from the code:
str = cell.toString();
if (str != "" || str != null) {
System.out.println("Cell is a string");
num = Double.parseDouble(str);
} else {
System.out.println("Cell is numeric.");
num = cell.getNumericCellValue();
}
where the cell
is the last cell in the document that's not empty or null. When I try to print the first cell that's not empty or null, it prints nothing, so I think I'm not accessing it correctly.
© Stack Overflow or respective owner