如何使用POI处理旧的excel .xls文件? [英] How to process old excel .xls files using POI?

查看:225
本文介绍了如何使用POI处理旧的excel .xls文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从jxl切换到poi,因为POI具有更多的功能。但是,我无法处理以旧格式生成的xls文件。现在我得到这个错误:


org.apache.poi.hssf.OldExcelFormatException:提供的电子表格
似乎是Excel 5.0 / 7.0(BIFF5)格式。 POI仅支持BIFF8
格式(从Excel版本97/2000 / XP / 2003)


现在我正在考虑使用两个JXL作为POI的井,取决于xls版本,所以对于旧格式xls文件我将使用jxl,而对于较新的版本,我将使用POI。这是一个很好的解决方案?有没有其他选择?

解决方案

对于旧的Excel格式文件,您有以下选择:


  1. HSSF POI 执行Excel '97(-2007)文件格式。


  2. JXL 也可以处理某些情况。

  3. 使用 JDBC / ODBC 驱动程序。它不像 HSSF 那么灵活,但对于某些旧格式,它是提取信息的唯一方法。


I switched from jxl to poi since POI has more features. However, I wasn't able to process the xls files that were generated in the old format. Now I am getting this error:

org.apache.poi.hssf.OldExcelFormatException: The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)

Now I am thinking to use both JXL as wells as POI depending on the xls version so for old format xls files I will use jxl while for newer versions I will use POI. Is this a good solution? Are there any alternatives?

解决方案

For old Excel format files, you have the following alternatives:

  1. HSSF, the POI implementation of the Excel '97(-2007) file format.
    • If you just want to extract the textual content, then you can use OldExcelExtractor which will pull only the text and numbers from the file.
    • If you need the values from a specific cells, then you'll need to take an approach a bit like OldExcelExtractor, process the file at the record level, and check for the co-ordinates on OldStringRecord, NumberRecord, OldFormulaRecord and friends.
  2. Like you already mentioned, JXL can handle some cases too.
  3. Use a JDBC/ODBC driver. It is not as flexible as HSSF but for some old formats it is the only way to extract the information.

这篇关于如何使用POI处理旧的excel .xls文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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