【发布时间】:2018-11-05 08:25:57
【问题描述】:
我想读取由 Power Builder 应用生成的 Excel 文件(Office 版本 4)。 这是代码:
File xls = new File("D:/excel.xls");
InputStream fis = new FileInputStream(xls);
HSSFWorkbook book = new HSSFWorkbook(fis);
当我尝试使用 POI 库 v3.17 读取 Excel 文件时,它会抛出此异常:
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)
由于 Excel 文件是一个非常旧的版本,我尝试使用 POI v3.0-FINAL 读取它(我找不到旧版本)并抛出此异常:
java.io.IOException: Invalid header signature; read 4503608217567241, expected -2226271756974174256
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:100)
我尝试使用 ODBC 读取 Excel 文件
String myDB = "jdbc: odbc: Driver = {Microsoft Excel Driver (*.xls)}; DBQ = d: /excel.xls;" + "DriverID = 22; READONLY = false";
Connection with = DriverManager.getConnection (myDB, "", "");
但它会抛出异常:
java.sql.SQLException: [Microsoft] [ODBC Driver Manager] The name of
the data source is not found and no default drivers were specified
我也试过用 jxl 库读取 Excel 文件
Workbook workbook = Workbook.getWorkbook (new File ("d:/excel.xls"));
但是抛出这个异常:
jxl.read.biff.BiffException: Unable to recognize OLE stream
谁能帮我阅读带有任何 Java 库的 Excel 文件版本 4 (1994)?
我使用的是 JDK 1.7
【问题讨论】:
标签: java excel apache-poi excel-4.0