我正在尝试使用 Java 代码读取 Excel 文件,但是出现以下错误:
jxl.read.biff.BiffException:无法识别 OLE 流
当我在网上搜索时,我发现 jExcel 仅支持 excel 2003,当 2007 年制作 excel 时出现此错误,我只保存了 97-2003 格式的 excel,但我仍然遇到这个问题
JExcel API 不支持 excel 2007,你可以使用Apache POI HSSF/XSSF
这是从站点读取和重写工作簿的示例代码
InputStream inp = new FileInputStream("workbook.xls");
//InputStream inp = new FileInputStream("workbook.xlsx");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(3);
if (cell == null)
cell = row.createCell(3);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
我没有 JExcel 的经验,但我相信你认为问题是文件格式之一是正确的。我建议你试试Apache POI项目。我广泛使用它来读写 Excel 电子表格。它将读取从 Excel 5.0 开始 IIRC 创建的任何电子表格,并支持 .xsl 和 .xslx 文件类型。
我使用 JExcel 很长时间了,但从来没有遇到过这种问题。我认为您的文件不是 XLS 格式。您尝试创建一个新的 Excel 文件并尝试读取它。