在 Java 中读取 Excel 工作表的更好 API 是什么 - JXL 或 Apache POI [英] What is the better API to Reading Excel sheets in java - JXL or Apache POI
问题描述
这 2 个 API 中哪个更易于读取/写入/编辑 Excel 表格?这些 API 不支持 CSV 扩展吗?
Which of the 2 APIs is simpler to read/write/edit excel sheets ? Do these APIs not support CSV extensions ?
对 file.xls 和 file.xlsx 使用 JXL,我得到如下异常:
Using JXL for file.xls and file.xlsx, I get an exception like:
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:268)
at core.ReadXLSheet.contentReading(ReadXLSheet.java:46)
at core.ReadXLSheet.init(ReadXLSheet.java:22)
at core.ReadXLSheet.main(ReadXLSheet.java:72)
.xls 和 .xlsx 扩展名.我使用的 Java 版本是:JDK1.6
Both for .xls and .xlsx extensions. Java Version I am using is : JDK1.6
推荐答案
JXL 我都用过(现在是JExcel")和 Apache POI.一开始我用的是JXL,现在我用的是Apache POI.
I have used both JXL (now "JExcel") and Apache POI. At first I used JXL, but now I use Apache POI.
首先,以下是两个 API 具有相同最终功能的地方:
First, here are the things where both APIs have the same end functionality:
- 两者都是免费的
- 单元格样式:对齐、背景(颜色和图案)、边框(类型和颜色),字体支持(字体名称、颜色、大小、粗体、斜体、删除线、下划线)
- 公式
- 超链接
- 合并单元格区域
- 行和列的大小
- 数据格式:数字和日期
- 单元格内的文本换行
- 冻结窗格
- 页眉/页脚支持
- 读取/写入现有的和新的电子表格
- 两者都尝试尽可能完整地保留他们读取的电子表格中的现有对象.
但是,有很多不同之处:
However, there are many differences:
- 也许最显着的区别是 Java JXL 不支持 Excel 2007+.xlsx"格式;它只支持旧的 BIFF(二进制).xls"格式.Apache POI 通过通用设计同时支持两者.
- 此外,JXL API 的 Java 部分上次更新是在 2009 年(3 年零 4 个月前,我写这篇文章),尽管它看起来像一个 C# API.Apache POI 得到积极维护.
- JXL 不支持条件格式,而 Apache POI 支持,尽管这并不重要,因为您可以使用自己的代码有条件地格式化单元格.
- JXL 不支持 rich text 格式,即文本字符串中的不同格式;Apache POI 确实支持它.
- JXL 仅支持某些文本旋转:水平/垂直、+/- 45 度和堆叠;Apache POI 支持任意整数度数加上堆叠.
- JXL 不支持绘制形状;Apache POI 可以.
- JXL 支持大多数页面设置设置,例如横向/纵向、边距、纸张大小和缩放.Apache POI 支持所有这些以及重复行和列.
- JXL 不支持拆分窗格;Apache POI 可以.
- JXL 不支持图表创建或操作;Apache POI 中尚不提供这种支持,但 API 正在慢慢开始形成.
- Apache POI 拥有比 JXL 更广泛的文档和示例集.
- Perhaps the most significant difference is that Java JXL does not support the Excel 2007+ ".xlsx" format; it only supports the old BIFF (binary) ".xls" format. Apache POI supports both with a common design.
- Additionally, the Java portion of the JXL API was last updated in 2009 (3 years, 4 months ago as I write this), although it looks like there is a C# API. Apache POI is actively maintained.
- JXL doesn't support Conditional Formatting, Apache POI does, although this is not that significant, because you can conditionally format cells with your own code.
- JXL doesn't support rich text formatting, i.e. different formatting within a text string; Apache POI does support it.
- JXL only supports certain text rotations: horizontal/vertical, +/- 45 degrees, and stacked; Apache POI supports any integer number of degrees plus stacked.
- JXL doesn't support drawing shapes; Apache POI does.
- JXL supports most Page Setup settings such as Landscape/Portrait, Margins, Paper size, and Zoom. Apache POI supports all of that plus Repeating Rows and Columns.
- JXL doesn't support Split Panes; Apache POI does.
- JXL doesn't support Chart creation or manipulation; that support isn't there yet in Apache POI, but an API is slowly starting to form.
- Apache POI has a more extensive set of documentation and examples available than JXL.
此外,POI 不仅包含主要的用户模型"API,还包含一个基于事件的 API(如果您只想阅读电子表格内容).
Additionally, POI contains not just the main "usermodel" API, but also an event-based API if all you want to do is read the spreadsheet content.
总而言之,由于更好的文档、更多的功能、积极的开发以及 Excel 2007+ 格式的支持,我使用了 Apache POI.
In conclusion, because of the better documentation, more features, active development, and Excel 2007+ format support, I use Apache POI.
这篇关于在 Java 中读取 Excel 工作表的更好 API 是什么 - JXL 或 Apache POI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!