I want to read an Excel file (version 4 of Office) that has been generated by a Power Builder app. This is the code:
File xls = new File("D:/excel.xls");
InputStream fis = new FileInputStream(xls);
HSSFWorkbook book = new HSSFWorkbook(fis);
When I try to read the Excel file with the POI library v3.17, it throws this exception:
org.apache.poi.poifs.filesystem.NotOLE2FileException: Invalid header signature; read 0x0010000200040009, expected 0xE11AB1A1E011CFD0 - Your file appears not to be a valid OLE2 document
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:144)
As the Excel file is a very old version I try to read it with the POI v3.0-FINAL (I cannot find an older version) and throws this exception:
java.io.IOException: Invalid header signature; read 4503608217567241, expected -2226271756974174256
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:100)
I tried to read the Excel file with ODBC
String myDB = "jdbc: odbc: Driver = {Microsoft Excel Driver (*.xls)}; DBQ = d: /excel.xls;" + "DriverID = 22; READONLY = false";
Connection with = DriverManager.getConnection (myDB, "", "");
But it throws the exception:
java.sql.SQLException: [Microsoft] [ODBC Driver Manager] The name of
the data source is not found and no default drivers were specified
I have also tried to read the Excel file with the jxl library
Workbook workbook = Workbook.getWorkbook (new File ("d:/excel.xls"));
But throw this exception:
jxl.read.biff.BiffException: Unable to recognize OLE stream
Can anyone help me read an Excel file version 4 (1994) with any Java library?
I'm using JDK 1.7
The Apache POI HSSF format is for the .xls files. The file you attempted to read is an .xml. Try using the XSSF classes.
XSSFWorkbook book = new XSSFWorkbook(fis);