如何使用POI处理旧的excel .xls文件? [英] How to process old excel .xls files using POI?
问题描述
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格式文件,您有以下选择:
- HSSF ,
POI
执行Excel '97(-2007)文件格式。
- 如果您只想提取文字内容,那么您可以使用 OldExcelExtractor ,它只会从文件中拉出
文本和数字。 - 如果您需要特定单元格的值,则需要使用
方法,如OldExcelExtractor
,在文件
级别处理文件,并检查 OldStringRecord , NumberRecord , OldFormulaRecord 和朋友。
- 如果您只想提取文字内容,那么您可以使用 OldExcelExtractor ,它只会从文件中拉出
- JXL 也可以处理某些情况。
- 使用 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:
- 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.
- Like you already mentioned, JXL can handle some cases too.
- 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屋!