I'm using Apache POI to read data from an Excel spreadsheet and sending a POST to a remote service.
While testing my implementation I found out it blew up with an exception when my method tried to parse an empty string into a BigDecimal. I discovered this is due to the fact that, according to the Apache POI documentation, getLastRowNum() may
rows which had content before and were set to empty later might still be counted as rows by Excel and Apache POI, so the result of this method will include such rows and thus the returned value might be higher than expected!
And lo and behold, it did return a bigger number than I had initially anticipated, forcing me to use the value in the first cell in the row as the exit condition for my loop, something like the following:
String productCode= excelMapper.getValueFromRow(r, "product_code");
while (productCode!= null && !productCode.isEmpty()) {
MyBeanClass bean = new MyBeanClass ();
r = sheet.getRow(i);
productCode = excelMapper.getValueFromRow(r, "cod_prodotto");
yada yada....
}
This works for my purposes, but I was wondering if there was a better way.