POI(對excel檔案物件操作)

2021-09-25 15:27:40 字數 1864 閱讀 4402

poi官方api文件

參考部落格1(使用例子)

參考部落格2(詳細講解hssfworkbook的屬性和方法)

參考部落格3

excel的xls檔案通過網頁上傳到後台處理,後台對xls檔案的處理需要使用到poi,

pom.xml檔案中先引入支援poi的依賴

<

dependency

>

<

groupid

>

org.apache.poi

groupid

>

<

artifactid

>

poiartifactid

>

<

version

>

3.16

version

>

dependency

>

<

dependency

>

<

groupid

>

org.apache.poi

groupid

>

<

artifactid

>

poi-ooxml

artifactid

>

<

version

>

3.16

version

>

dependency

>

前端通過form表單的multipart資料形式上傳excel檔案

<

div>

<

form

method

="post"

action

="/cyberspace/main/informationbatchadd.do"

enctype

="multipart/form-data">

<

input

type

="file"

id="excelfile"

name

="file"/>

<

button

type

="submit">

批量上傳

button

>

form

>

div>

後台使用post接收multiparthttpservletrequest型別資料,獲取上傳檔案,轉換為輸入流,再轉換為處理xls檔案的類hssfworkbook類(xsshworkbook類是處理xlsx檔案)

//獲取multipart檔案物件

multipartfile filefile = request.getfile(「file」);

//檔案物件轉換成輸入流

inputstream in = filefile.getinputstream();

//輸入流轉換為怎麼處理xls檔案的類

hssfworkbook readwb = new hssfworkbook(in);

readwb.getnumberofsheets  獲取工作表數量

hssfsheet sheet = readwb.getsheetat(0);   獲取0工作表物件

sheet.getlastrownum()     獲取行數

hssfrow hssfrow = sheet.getrow(2);   獲取2行物件

hssfrow.getphysicalnumberofcells();   獲取一行中單元格數量   

hssfrow.getcell(3)           獲取一行中第4個單元格物件

getstringcellvalue()    獲取單元格中的值

POI 操作 EXCEL檔案

1.最新的poi工具包 poi 主頁 快速上手使用poi hssf 2 excel 結構 hssfworkbook excell 文件物件介紹 hssfsheet excell的表單 hssfrow excell的行 hssfcell excell的格仔單元 hssffont excell字型 hs...

poi操作excel檔案

讀取檔案 2003 xls 讀取 param path throws ioexception suppresswarnings deprecation public static void readexcel string path throws ioexception system.out.pri...

poi對excel操作筆記

poi是apache提供的乙個讀寫excel文件的開源元件,在操作excel時常要合併單元格,合併單元格的方法是 sheet.addmergedregion new cellrangeaddress 1,1,0,2 自適應列寬度 sheet.autosizecolumn 1 sheet.autosi...