I have a problem with Apache POI project.
I failed to use XSSF and HSSF in the \"Same Java Class\". Which jar should I dow
Aside from the "standard" SS package solution, you can also simply use an if statement to correctly load the right workbook format into an Workbook interface object, like so:
Workbook workbook; //<-Interface, accepts both HSSF and XSSF.
File file = new File("YourExcelFile.xlsx");
if (FileUtils.getFileExt(file).equalsIgnoreCase("xls")) {
workbook = new HSSFWorkbook(new FileInputStream(file));
} else if (FileUtils.getFileExt(file).equalsIgnoreCase("xlsx")) {
workbook = new XSSFWorkbook(new FileInputStream(file));
} else {
throw new IllegalArgumentException("Received file does not have a standard excel extension.");
}