POI (excel) - API使用与参考

本文介绍了Apache POI项目的HSSF、XSSF和SXSSF,分别用于处理不同版本的Excel文件。HSSF支持低版本(.xls),XSSF支持高版本(.xlsx),而SXSSF则是在XSSF基础上提供低内存占用的解决方案。文章还详细对比了各种API的特性和适用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【1】HSSF,XSSF and SXSSF

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支持低版本的(拓展名为 .xls);XSSF支持高版本的(拓展名为 .xlsx)。

HSSF and XSSF provides ways to read spreadsheets create, modify, read and write XLS spreadsheets.

They provide:

  • low level structures for those with special needs
  • an eventmodel api for efficient read-only access
    //如果是只读,就是用事件模型
  • a full usermodel api for creating, reading and modifying XLS files
    //如果需要创建和读写,那么使用用户模型(包的区别)
  • 用户模型比事件模型有更高的内存占用,但是更优良。

XSSF 比HSSF更优良,内存占用也更高。可以通过这两个api访问并修改excel。

SXSSF(拥有流的特性)是XSSF的扩展,拥有XSSF特性却是低内存占用的。

操作表格的时候不提供所有行的访问权限(用到取到,不用存盘)。

以下三个方面是SXSSF不支持的:

Only a limited number of rows are accessible at a point in time.
Sheet.clone() is not supported.
Formula evaluation is not supported

这里写图片描述

参考三者说明(https://poi.apache.org/spreadsheet/index.html)。


【2】 Different ways

There are a few different ways to access the HSSF API. These have different characteristics, so you should read up on all to select the best for you.

User API (HSSF and XSSF)
Event API (HSSF Only)
Event API with extensions to be Record Aware (HSSF Only)
XSSF and SAX (Event API)
SXSSF (Streaming User API)
Low Level API

这里写图片描述

参考(https://poi.apache.org/spreadsheet/how-to.html#user_api)。


【3】如何快速使用HSSF和XSSF

参考Quick Guide

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

流烟默

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值