I'm reading an XLS sheet through Apache POI and I'm having trouble figuring out why this code is not reporting the year of dates correctly.
The Excel sheet lists data like this:
I added out.println so I can monitor the output which appears like this:
As you see above, the code strips out the "20" from 2019 which displays correctly when outputting the contents of cell. Any idea why, and any idea how I can fix it? It seems to work fine if I use cell.iterator, but when I changed the code to account for nulls it no longer works.
for (int r = 1; r < rows; r++) {
row = (XSSFRow) sheet.getRow(r);
if (row != null) {
for (int c = 0; c < cols; c++) {
cell = row.getCell((short) c);
out.println("cell = " + cell);
String x;
DataFormatter dataFormatter = new DataFormatter();
x = dataFormatter.formatCellValue(cell);
out.println("X + " + x + "<br/>");
}