在Java - JXL或Apache POI中阅读Excel表格的API越好 [英] What is the better API to Reading Excel sheets in java - JXL or Apache POI

查看:90
本文介绍了在Java - JXL或Apache POI中阅读Excel表格的API越好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2个API中的哪一个更容易读/写/编辑excel表?
这些API不支持CSV扩展?



使用JXL for file.xls和file.xlsx,我会收到一个例外:

  jxl.read.biff.BiffException:无法在jxl.read.biff.CompoundFile中识别OLE流
。< init>(CompoundFile.java:116)
在jxl.read.biff.File。< init>(File.java:127)
在jxl.Workbook.getWorkbook(Workbook.java :268)
在core.ReadXLSheet.contentReading(ReadXLSheet.java:46)
在core.ReadXLSheet.init(ReadXLSheet.java:22)
在core.ReadXLSheet.main(ReadXLSheet。 java:72)

两种.xls和.xlsx扩展名。
我使用的Java版本是:JDK1.6

解决方案

我使用了 JXL (现在是JExcel)和 Apache POI 。起初我使用了JXL,但现在我使用Apache POI。



首先,这两个API都有相同的最终功能:




  • 两个都是免费的

  • 单元格样式:对齐方式,背景(颜色和图案),边框
    (类型和颜色),字体支持(字体名称,颜色,大小,粗体,
    斜体,删除,下划线)

  • 公式

  • 超链接

  • 合并的单元格区域

  • 行和列的大小

  • 数据格式:数字和日期

  • 单元格内的文本换行

  • 冻结窗格

  • 页眉/页脚支持

  • 阅读/写现有和新的电子表格

  • 两者都尽可能保持现有对象在电子表格中的完整读取。



但是,有很多区别:




  • 也许最重要的区别是Java JXL不支持Excel 2007+.xls x格式;它只支持旧的BIFF(二进制).xls格式。 Apache POI支持通用的设计。另外,JXL API的Java部分最近更新于2009年(3年,4个月前,因为我写这个),虽然它看起来就像有一个C#API。 Apache POI被积极维护。

  • JXL不支持条件格式化,但是Apache POI虽然不是很重要,但可以通过自己的代码有条件地格式化单元格。 >
  • JXL不支持 文本格式,即文本字符串中不同的格式化; Apache POI确实支持它。

  • JXL仅支持某些文本旋转:水平/垂直,+/- 45度和堆叠; Apache POI支持任意整数的加权积分。

  • JXL不支持绘图形状; Apache POI。

  • JXL支持大多数页面设置设置,如横向/纵向,边距,纸张尺寸和缩放。 Apache POI支持所有这些加重复行和列。

  • JXL不支持拆分窗格; Apache POI。

  • JXL不支持图表创建或操作; Apache POI中尚未提供支持,但是API正在慢慢开始。

  • Apache POI具有比JXL更多的文档和示例。



此外,POI不仅包含主要的usermodelAPI,而且还包含一个基于事件的API,如果您想要的是读取电子表格内容总结来说,由于更好的文档,更多功能,主动开发和Excel 2007+格式支持,我使用Apache POI。


Which of the 2 APIs is simpler to read/write/edit excel sheets ? Do these APIs not support CSV extensions ?

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)

Both for .xls and .xlsx extensions. Java Version I am using is : JDK1.6

解决方案

I have used both JXL (now "JExcel") and Apache POI. At first I used JXL, but now I use Apache POI.

First, here are the things where both APIs have the same end functionality:

  • Both are free
  • Cell styling: alignment, backgrounds (colors and patterns), borders (types and colors), font support (font names, colors, size, bold, italic, strikeout, underline)
  • Formulas
  • Hyperlinks
  • Merged cell regions
  • Size of rows and columns
  • Data formatting: Numbers and Dates
  • Text wrapping within cells
  • Freeze Panes
  • Header/Footer support
  • Read/Write existing and new spreadsheets
  • Both attempt to keep existing objects in spreadsheets they read in intact as far as possible.

However, there are many differences:

  • 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.

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.

In conclusion, because of the better documentation, more features, active development, and Excel 2007+ format support, I use Apache POI.

这篇关于在Java - JXL或Apache POI中阅读Excel表格的API越好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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