Reputation: 51039
I would like to be able to open Excel file of arbotrary type. Is it possible to select between HSSFWorkbook
and XSSFWorkbook
automatically?
Currently I write
Workbook workbook = new HSSFWorkbook(excelFile);
Can I write universal?
Upvotes: 1
Views: 1373
Reputation: 48326
Yes! All you need to do is use WorkbookFactory
As per this part of the docs, it's better to use a File
than an InputStream
. So, just do something like:
File file = new File("input.xls");
Workbook wb = WorkbookFactory.create(file);
That will create whichever of HSSFWorkbook
or XSSFWorkbook
your file needs
Upvotes: 5