You can use Apache Tika for that:
String parse(File xlsxFile) {
return new Tika().parseToString(xlsxFile);
}
Tika uses Apache POI for parsing XLSX files.
Here are some usage examples for Tiki.
Alternatively, if you want to handle each cell of the spreadsheet individually, here's one way to do this with POI:
void parse(File xlsx) {
try (XSSFWorkbook workbook = new XSSFWorkbook(xlsx)) {
// Handle each cell in each sheet
workbook.forEach(sheet -> sheet.forEach(row -> row.forEach(this::handle)));
}
catch (InvalidFormatException | IOException e) {
System.out.println("Can't parse file " + xlsx);
}
}
void handle(Cell cell) {
final String cellContent;
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
cellContent = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
cellContent = String.valueOf(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
cellContent = String.valueOf(cell.getBooleanCellValue());
break;
default:
cellContent = "Don't know how to handle cell " + cell;
}
System.out.println(cellContent);
}