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

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

问题描述

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

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:提供的电子表格似乎是 Excel 5.0/7.0 (BIFF5) 格式.POI 仅支持 BIFF8格式(来自 Excel 版本 97/2000/XP/2003)

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)

现在我想根据 xls 版本同时使用 JXL 和 POI,因此对于旧格式的 xls 文件,我将使用 jxl,而对于较新的版本,我将使用 POI.这是一个很好的解决方案吗?有没有其他选择?

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?

推荐答案

对于旧的 Excel 格式文件,您有以下替代方案:

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

  1. HSSF,Excel '97(-2007) 文件格式.
    • 如果您只想提取文本内容,则可以使用 OldExcelExtractor 将只提取文件中的文本和数字.
    • 如果您需要来自特定单元格的值,那么您需要采用方法有点像OldExcelExtractor,在记录处处理文件级别,并检查 OldStringRecordNumberRecordOldFormulaRecord 和朋友们.
  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.

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

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