Reputation: 61
I am trying to get data from an Excel file into my Spring(Java) web app. I am developing the system which should be suitable for both .xls and .xlsx Excel files. And I want to check whether the cellType of any cell is date, numeric, string, blank etc. for .xls file, mycode is like that:
while (cells.hasNext()) {
HSSFCell cell = (HSSFCell) cells.next();
if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
if (HSSFDateUtil.isCellDateFormatted(cell)) {
array.add(df.format(cell.getDateCellValue()));
} else {
int i = (int) cell.getNumericCellValue();
array.add(String.valueOf(i));
}
} else if (HSSFCell.CELL_TYPE_STRING == cell.getCellType()) {
array.add((cell.getStringCellValue()).trim());
} else if (HSSFCell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
array.add(cell.getBooleanCellValue() + " ");
} else if (HSSFCell.CELL_TYPE_BLANK == cell.getCellType()) {
array.add(" ");
}
}
Everythin is ok for .xls file. In .xls file
if (HSSFDateUtil.isCellDateFormatted(cell))
this code is checking whether the HSSFCell is date or not. And I want to do the same checking with .xlsx file. But I couldn't find any such method. Is there any such method for XSSFCell? I couldn't find Thanks in advance
Upvotes: 0
Views: 2882
Reputation: 1513
For XSSF, you can use DateUtil.isCellDateFormatted(cell) provided by the POI library, that would return boolean. POI DateUtil
Upvotes: 3