Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process old excel .xls files using POI?

Tags:

I switched from jxl to poi since POI has more features. However, I wasn't able to process the xls files that were generated in the old format. Now I am getting this error:

org.apache.poi.hssf.OldExcelFormatException: The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)

Now I am thinking to use both JXL as wells as POI depending on the xls version so for old format xls files I will use jxl while for newer versions I will use POI. Is this a good solution? Are there any alternatives?

like image 829
Wael Avatar asked Mar 11 '13 10:03

Wael


People also ask

Does Apache POI support XLS?

Apache POI is able to handle both XLS and XLSX formats of spreadsheets. Some important points about Apache POI API are: Apache POI contains HSSF implementation for Excel '97(-2007) file format i.e XLS. Apache POI XSSF implementation should be used for Excel 2007 OOXML (.


1 Answers

For old Excel format files, you have the following alternatives:

  1. HSSF, the POI implementation of the Excel '97(-2007) file format.
    • If you just want to extract the textual content, then you can use OldExcelExtractor which will pull only the text and numbers from the file.
    • If you need the values from a specific cells, then you'll need to take an approach a bit like OldExcelExtractor, process the file at the record level, and check for the co-ordinates on OldStringRecord, NumberRecord, OldFormulaRecord and friends.
  2. Like you already mentioned, JXL can handle some cases too.
  3. Use a JDBC/ODBC driver. It is not as flexible as HSSF but for some old formats it is the only way to extract the information.
like image 66
dan Avatar answered Sep 17 '22 18:09

dan