Java POI组件——总体概况

Java POI组件——总体概况_第1张图片

当前使用的是poi-3.15,下载地址如下
http://poi.apache.org/download.html

很多初学者在第一次接触Java操作office的POI组件时都有这样的疑惑——我该引入那些jar包呢?

当前的最新版本的POI组件是poi-3.15

Java POI组件——总体概况_第2张图片

我的经验是看官网说明。这种大型开源项目一般在官网都有很详尽的说明。

Apache POI - Component Overview
http://poi.apache.org/overview.html

Component Map

The Apache POI distribution consists of support for many document file formats. This support is provided in several Jar files. Not all of the Jars are needed for every format. The following tables show the relationships between POI components, Maven repository tags, and the project’s Jar files.

Apache的POI发行套件包含了对多种文档文件格式的支持。这些支持由多个Jar文件提供。不是每种格式都需要所有的Jar的。下表显示了POI中各组件之间的关系,Maven仓库标签,和项目的Jar文件。

Component Application type Maven artifactId Notes
POIFS OLE2 Filesystem poi Required to work with OLE2 / POIFS based files
HPSF OLE2 Property Sets poi
HSSF Excel XLS poi For HSSF only, if common SS is needed see below
HSLF PowerPoint PPT poi-scratchpad
HWPF Word DOC poi-scratchpad
HDGF Visio VSD poi-scratchpad
HPBF Publisher PUB poi-scratchpad
HSMF Outlook MSG poi-scratchpad
DDF Escher common drawings poi
HWMF WMF drawings poi-scratchpad
OpenXML4J OOXML poi-ooxml plus either poi-ooxml-schemas or ooxml-schemas and ooxml-security See notes below for differences between these options
XSSF Excel XLSX poi-ooxml
XSLF PowerPoint PPTX poi-ooxml
XWPF Word DOCX poi-ooxml
XDGF Visio VSDX poi-ooxml
Common SL PowerPoint PPT and PPTX poi-scratchpad and poi-ooxml SL code is in the core POI jar, but implementations are in poi-scratchpad and poi-ooxml.
Common SS Excel XLS and XLSX poi-ooxml WorkbookFactory and friends all require poi-ooxml, not just core poi

This table maps artifacts into the jar file name. “version-yyyymmdd” is the POI version stamp. You can see what the latest stamp is on the downloads page.

该表将软件组件映射到jar文件名。”version-yyyymmdd”就是POI版本的标记。你可以查看下载页面来获取最新版本的标记。

Maven artifactId Prerequisites JAR
poi commons-logging, commons-codec, commons-collections, log4j poi-version-yyyymmdd.jar
poi-scratchpad poi poi-scratchpad-version-yyyymmdd.jar
poi-ooxml poi, poi-ooxml-schemas poi-ooxml-version-yyyymmdd.jar
poi-ooxml-schemas xmlbeans poi-ooxml-schemas-version-yyyymmdd.jar
poi-examples poi, poi-scratchpad, poi-ooxml poi-examples-version-yyyymmdd.jar
ooxml-schemas xmlbeans ooxml-schemas-1.3.jar
ooxml-security xmlbeans For signing: bcpkix-jdk15on, bcprov-jdk15on, xmlsec, slf4j-api ooxml-security-1.1.jar



xls 与 xlsx 的区别

  • 2003版本的.xls一张sheet表允许存2^16 = 次方行数据,2^8 = 256列数据,
  • 2007版本以上的.xlsx一张sheet表允许存的数据就更大了,是百万级别的。行: 2^20 = 1048576; 列:2^14 = 16384 行。

HSSF、XSSF、SXSSF 的区别

  • HSSF是POI工程对Excel 97(-2007)文件操作的纯Java实现
  • XSSF是POI工程对Excel 2007 OOXML (.xlsx)文件操作的纯Java实现
  • XSSF是POI 3.8版本开始,提供了一种基于XSSF的低内存占用的API
    SXSSF通过一个滑动窗口来限制访问Row的数量从而达到低内存占用的目录,XSSF可以访问所有行。旧的行数据不再出现在滑动窗口中并变得无法访问,与此同时写到磁盘上。
    在自动刷新的模式下,可以指定窗口中访问Row的数量,从而在内存中保持一定数量的Row。当达到这一数量时,在窗口中产生新的Row数据,并将低索引的数据从窗口中移动到磁盘中。
    或者,滑动窗口的行数可以设定成自动增长的。它可以根据需要周期的根据一次明确的flushRow(int keepRows)调用来进行修改。
    注意:针对 SXSSF Beta 3.8下,会有临时文件产生,比如:
    poi-sxssf-sheet4654655121378979321.xml
    文件位置:java.io.tmpdir这个环境变量下的位置
    Windows 7下是C:\Users\xxxxxAppData\Local\Temp
    Linux下是 /var/tmp/
    要根据实际情况,看是否删除这些临时文件
    官方也提供了一些解决方式:
    https://issues.apache.org/bugzilla/show_bug.cgi?id=53493
    与XSSF的对比
    在一个时间点上,只可以访问一定数量的数据
    不再支持Sheet.clone()
    不再支持公式的求值

你可能感兴趣的:(——,Java,POI,操作,Office)