java 如何使用jexcel读取excel?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3413231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:43:50  来源:igfitidea点击:

How to read excel using jexcel?

javajexcelapi

提问by Simran

i am trying to read an Excel file using Java code however i am getting following error :

我正在尝试使用 Java 代码读取 Excel 文件,但是出现以下错误:

jxl.read.biff.BiffException: Unable to recognize OLE stream

jxl.read.biff.BiffException:无法识别 OLE 流

when i searched on net i found jExcel supports only upto excel 2003, and this error comes when excel is made in 2007 bt i have saved my excel in 97-2003 format only and i am still getting this problem

当我在网上搜索时,我发现 jExcel 仅支持高达 excel 2003,并且在 2007 年制作 excel 时出现此错误 bt 我仅以 97-2003 格式保存了我的 excel,但我仍然遇到此问题

回答by urmalp

JExcel API does not support excel 2007,you can use Apache POI HSSF/XSSF

JExcel API 不支持 excel 2007,您可以使用Apache POI HSSF/XSSF

here is sample code for Reading and Rewriting Workbooks from the site

这是从站点读取和重写工作簿的示例代码

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();

回答by wobblycogs

I've no experience of JExcel but I beleive you are correct in thinking that the problem is one of file formats. I suggest you try the Apache POIproject. I use it extensively to read and write Excel spreadsheets. It will read any spreadsheet created from Excel 5.0 onwards IIRC and supports both .xsl and .xslx file types.

我没有 JExcel 的经验,但我相信您认为问题是一种文件格式是正确的。我建议您尝试Apache POI项目。我广泛使用它来读写 Excel 电子表格。它将读取从 Excel 5.0 及 IIRC 创建的任何电子表格,并支持 .xsl 和 .xslx 文件类型。

回答by Rakesh Goyal

I am using JExcel since long time but never got this kind of problem. I think your file is not in XLS format. You try to create a new Excel file and try to read it.

我很长时间以来一直在使用 JExcel,但从未遇到过这种问题。我认为您的文件不是 XLS 格式。您尝试创建一个新的 Excel 文件并尝试读取它。