Apache POI介紹

POI簡介
    Apache POI是Apache軟件基金會的開放源碼函式庫,POI提供API給Java程序對Microsoft Office格式檔案讀和寫的功能。自2009-09-28後,推出了3.5版本,提供了對Office2007的支持;

 

HSSF概況
    HSSF 是Horrible SpreadSheet Format的縮寫,通過HSSF,你可以用純Java代碼來讀取、寫入、修改Excel文件。HSSF 爲讀取操作提供了兩類API:usermodel和eventusermodel,即“用戶模型”和“事件-用戶模型”。

 

jar包簡單概括
poi-version-yyyymmdd.jar

用於操作.xls文件;依賴於commons-logging, commons-codec, log4j;


poi-scratchpad-version-yyyymmdd.jar

用於操作.ppt、.doc、.vsd、.pub、.msg文件;依賴於poi;

 

poi-ooxml-version-yyyymmdd.jar、poi-ooxml-schemas-version-yyyymmdd.jar

用於操作.xlsx、.pptx、docx文件;依賴於poi, dom4j,xmlbeans, stax-api-1.0.1;操作Excel主要是指ss包、xssf包;


也就是目錄lib下面是poi依賴的jar包,目錄ooxml-lib下面是poi-ooxml依賴的jar包;

 

組件 APIs
Excel (SS=HSSF+XSSF)
Word (HWPF+XWPF)
PowerPoint (HSLF+XSLF)
OpenXML4J (OOXML)
OLE2 Filesystem (POIFS)
OLE2 Document Props (HPSF)
Outlook (HSMF)
Visio (HDGF)
Publisher (HPBF)

 

API下載:http://poi.apache.org/

組件參考http://poi.apache.org/overview.html

doc參考http://poi.apache.org/apidocs/index.html

maven中央倉庫搜索http://search.maven.org/
maven安裝
先下載API包後,解壓,然後CMD切換到該目錄下(前提,本機已經安裝Maven);
執行下面命令;
mvn install:install-file -DgroupId=stax -DartifactId=stax-api -Dversion=1.0.1 -Dpackaging=jar -Dfile=stax-api-1.0.1.jar
mvn install:install-file -DgroupId=org.apache.xmlbeans -DartifactId=xmlbeans -Dversion=2.3.0 -Dpackaging=jar -Dfile=xmlbeans-2.3.0.jar
mvn install:install-file -DgroupId=org.apache.poi -DartifactId=poi -Dversion=3.9 -Dpackaging=jar -Dfile=poi-3.9-20121203.jar
mvn install:install-file -DgroupId=org.apache.poi -DartifactId=poi-scratchpad -Dversion=3.9 -Dpackaging=jar -Dfile=poi-scratchpad-3.9-20121203.jar
mvn install:install-file -DgroupId=org.apache.poi -DartifactId=ooxml-schemas -Dversion=3.9 -Dpackaging=jar -Dfile=poi-ooxml-schemas-3.9-20121203.jar
mvn install:install-file -DgroupId=org.apache.poi -DartifactId=poi-ooxml -Dversion=3.9 -Dpackaging=jar -Dfile=poi-ooxml-3.9-20121203.jar

 

pom.xml設置:
<dependency>
 <groupId>org.apache.poi</groupId>
 <artifactId>poi</artifactId>
 <version>${poi.version}</version>
<exclusions>
<exclusion>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
</exclusion>
 <exclusion>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
 <groupId>org.apache.poi</groupId>
 <artifactId>poi-scratchpad</artifactId>
 <version>${poi.version}</version>
</dependency>
<dependency>
 <groupId>org.apache.poi</groupId>
 <artifactId>ooxml-schemas</artifactId>
 <version>${poi.version}</version>
 <exclusions>
  <exclusion>
 <groupId>stax</groupId>
 <artifactId>stax-api</artifactId>
    </exclusion>
    <exclusion>
 <groupId>org.apache.xmlbeans</groupId>
 <artifactId>xmlbeans</artifactId>
    </exclusion>
</exclusions>
</dependency>
<dependency>
 <groupId>org.apache.poi</groupId>
 <artifactId>poi-ooxml</artifactId>
 <version>${poi.version}</version>
 <exclusions>
<exclusion>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>

 

POI EXCEL文檔結構類
HSSFWorkbook excel文檔對象
HSSFSheet excel的sheet
HSSFRow excel的行
HSSFCell excel的單元格
HSSFFont excel字體
HSSFName 名稱
HSSFDataFormat 日期格式
HSSFHeader sheet頭
HSSFFooter sheet尾
HSSFCellStyle cell樣式
HSSFDateUtil 日期
HSSFPrintSetup 打印
HSSFErrorConstants 錯誤信息表

 

參考:http://blog.csdn.net/xjun15/article/details/5805429


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章