POI-HSSF and POI-XSSF/SXSSF - Java API To Access Microsoft Excel Format Files(POI-HSSF 和 POI-XSSF/SXSSF - 使用Java API访问Microsoft Excel 格式文件)

Overview(概述)

Overview(概述)

HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.(HSSF是POI项目对Excel '97(-2007) 文件格式的纯 Java 实现。XSSF是POI项目对Excel 2007 OOXML (.xlsx) 文件格式的纯Java实现。)

HSSF and XSSF provides ways to read spreadsheets create, modify, read and write XLS spreadsheets. They provide:(HSSF 和 XSSF 提供了读取电子表格创建、修改、读取和写入 XLS 电子表格的方法。他们提供:)

  • low level structures for those with special needs(为有特殊需要的靓仔提供低层结构)
  • an eventmodel api for efficient read-only access(用于高效只读访问的eventmodel(事件模型) API)
  • a full usermodel api for creating, reading and modifying XLS files(用于创建、读取和修改 XLS 文件的完整usermodel(用户模型) API)

For people converting from pure HSSF usermodel, who wish to use the joint SS Usermodel for HSSF and XSSF support, then see the ss usermodel converting guide.(对于从纯 HSSF usermodel转换的人,如果希望使用联合 SS Usermodel来支持 HSSF 和 XSSF,请参阅 ss 用户模型转换指南)

An alternate way of generating a spreadsheet is via the Cocoon serializer (yet you'll still be using HSSF indirectly). With Cocoon you can serialize any XML datasource (which might be a ESQL page outputting in SQL for instance) by simply applying the stylesheet and designating the serializer.(生成电子表格的另一种方法是通过Cocoon序列化程序(但您仍将间接使用 HSSF)。使用 Cocoon,您可以通过简单地应用样式表并指定序列化程序来序列化任何 XML 数据源(例如,可能是用 SQL 输出的 ESQL 页面)。)

If you're merely reading spreadsheet data, then use the eventmodel api in either the org.apache.poi.hssf.eventusermodel package, or the org.apache.poi.xssf.eventusermodel package, depending on your file format.(如果您只是读取电子表格数据,请使用 org.apache.poi.hssf.eventusermodel 包或 org.apache.poi.xssf.eventusermodel 包中的 eventmodel api,具体取决于您的文件格式。)

If you're modifying spreadsheet data then use the usermodel api. You can also generate spreadsheets this way.(如果您正在修改电子表格数据,请使用 usermodel api。您也可以通过这种方式生成电子表格。)

Note that the usermodel system has a higher memory footprint than the low level eventusermodel, but has the major advantage of being much simpler to work with. Also please be aware that as the new XSSF supported Excel 2007 OOXML (.xlsx) files are XML based, the memory footprint for processing them is higher than for the older HSSF supported (.xls) binary files.(请注意,usermodel 系统比低级 eventusermodel 具有更高的内存占用,但主要优点是使用起来更简单。另请注意,由于新的 XSSF 支持的 Excel 2007 OOXML (.xlsx) 文件是基于 XML 的,因此处理它们的内存占用高于旧的 HSSF 支持的 (.xls) 二进制文件。)

SXSSF (Since POI 3.8 beta3)(SXSSF(自 POI 3.8 beta3 起))

Since 3.8-beta3, POI provides a low-memory footprint SXSSF API built on top of XSSF.(从 3.8-beta3 开始,POI 提供了基于 XSSF 构建的低内存占用 SXSSF API。)

SXSSF is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. SXSSF achieves its low memory footprint by limiting access to the rows that are within a sliding window, while XSSF gives access to all rows in the document. Older rows that are no longer in the window become inaccessible, as they are written to the disk.(SXSSF是XSSF的API兼容的流式扩展,可在必须生成非常大的电子表格且堆空间有限时使用。XSSF 允许访问文档中的所有行,而SXSSF通过限制对滑动窗口内的行的访问来实现其低内存占用。SXSSF不在窗口中的旧行将不可访问,因为它们已被写入磁盘。)

In auto-flush mode the size of the access window can be specified, to hold a certain number of rows in memory. When that value is reached, the creation of an additional row causes the row with the lowest index to to be removed from the access window and written to disk. Or, the window size can be set to grow dynamically; it can be trimmed periodically by an explicit call to flushRows(int keepRows) as needed.(在自动刷新模式下,可以指定访问窗口的大小,以在内存中保存一定数量的行。当达到该值时,创建附加行会导致索引最低的行从访问窗口中删除并写入磁盘。或者,可以将窗口大小设置为动态增长;它可以根据需要通过显式调用 flushRows(int keepRows)方法进行清理。)

Due to the streaming nature of the implementation, there are the following limitations when compared to XSSF:(由于实现的流性质,与 XSSF 相比存在以下限制:)

  • Only a limited number of rows are accessible at a point in time.(在某个时间点只能访问有限数量的行。)
  • Sheet.clone() is not supported.(不支持 Sheet.clone()。)
  • Formula evaluation is not supported(不支持公式评估)

See more details at SXSSF How-To(SXSSF How-To 中查看更多详细信息)

The table below synopsizes the comparative features of POI's Spreadsheet API:(下表概括了 POI 的电子表格 API 的比较特性:)

Spreadsheet API Feature Summary(电子表格 API 功能摘要)

Spreadsheet API Feature Summary

by Andrew C. Oliver, Nicola Ken Barozzi(作者:Andrew C. Oliver、Nicola Ken Barozzi)

 
中英文 | 中文 | 英文