在Java中读取Excel文件 [英] Reading excel file in java

查看:106
本文介绍了在Java中读取Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Java读取Excel文件.我已经下载了jxl.jar文件,并在eclipse中设置了类路径.但是我无法执行该程序,因为它抛出BiffException.像这样:

I want to read an excel file in java. I hava downloaded the jxl.jar file and I have set classpath in eclipse.But Iam not able to execute the program because it throws BiffException. Like this:

jxl.read.biff.BiffException: Unable to recognize OLE stream
    at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
    at jxl.read.biff.File.<init>(File.java:127)
    at jxl.Workbook.getWorkbook(Workbook.java:221)
    at jxl.Workbook.getWorkbook(Workbook.java:198)
    at excel.read(excel.java:40)
    at excel.main(excel.java:69)


我可以知道为什么会引发异常以及如何解决该异常.


May I know why it is throwing exception and how can I resolve this.

推荐答案

使用复合文档文件存储具有几张工作表(从BIFF5开始)的Excel工作簿.格式(也称为OLE2存储文件格式或与Microsoft Office兼容的存储文件格式).它包含几个用于不同类型数据的流.
有关复合文档文件格式的完整文档,请参见

http://sc.openoffice.org/compdocfileformat.pdf [
An Excel workbook with several sheets (from BIFF5 on) is stored using the compound document file format (also known as OLE2 storage file format or Microsoft Office compatible storage file format). It contains several streams for different types of data.
A complete documentation of the format of compound document files can be found at

http://sc.openoffice.org/compdocfileformat.pdf[^]

I think the exception mean that your parsing library can not recognise it(For example:biff5 format can not be parsed in POI and Jexcelapi). You can check your file version be open it in Office and click ''SAVE AS'',the format list in the filedialog is it''s current file version.


BiffException表示jexcel api无法识别文件格式和使用的文件.我在Office 2010中也遇到了同样的问题.

然后,我通过将文件另存为Office 2003-7 .xls文件解决了该问题.在office10或其他情况下可能会出现问题,但如果您将文件另存为Office 2003-7,那么我希望您的代码也能使用.
BiffException means that the jexcel api is not able to recognize the file format and the file u r using. I was also facing the same issue in Office 2010.

Then i resolved the problem by just saving the file as office 2003-7 .xls file. It may b problem in office10 or other case but if u will save file as office 2003-7 then I hope ur code will also work.


这篇关于在Java中读取Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆