POI之操作Excel表

2021-07-24 05:30:00 字數 2553 閱讀 7182

office 2003和office 2007及以上版本excel的區別:

excel 2003

excel 2007以上版本

技術背景

ole2(二進位制檔案)

ooxml(xml檔案)

行數(單sheet)

65536

1048576 列數

25565536

最後的效果圖:

excel 2003操作使用hssf

; //標題陣列

_row = _sheet.createrow(_rowno++);

_row.setheightinpoints(26);

for(int i = 0; i < title.length; ++i)

//處理內容

list_datalist = outproductservice.find(inputdate);

inputdate = inputdate.replacefirst("-0", "-").replacefirst("-", "年");

cellstyle _textcellstyle = settextcellstyle(_wb);

for(int i = 0; i < _datalist.size(); ++i)

bytearrayoutputstream _os = new bytearrayoutputstream();

_wb.write(_os);

downloadutil.download(_os, response, inputdate + "月份出貨表.xls");

_os.flush();

_os.close();

}

//大標題樣式

private cellstyle setbigtitlecellstyle(workbook workbook)

//小標題樣式

private cellstyle settitlecellstyle(workbook workbook)

//文字樣式

private cellstyle settextcellstyle(workbook workbook)

使用模板開發,模板效果圖:

//模板開發

excel 2007及以上版本使用xssf

org.apache.poi

poi-ooxml

3.9

//模板開發xssf

thread.sleep(1); //休息一下,防止對cpu占用

} long finishedtime = system.currenttimemillis(); //處理完成時間

system.out.println("finished execute time: " + (finishedtime - starttime)/1000 + "m");

fileoutputstream fout = new fileoutputstream(xlsfile);

wb.write(fout);

fout.flush();

fout.close();

long stoptime = system.currenttimemillis(); //寫檔案時間

system.out.println("write xlsx file time: " + (stoptime - starttime)/1000 + "m");

if(isclose)

}	

//close resource

private void close(resultset rs, statement stmt, connection conn ) throws sqlexception

使用POI操作Excel

apache的jakata專案poi http poi.apache.org 用來操作excel,並能滿足大部分需要.poi下面有幾個子專案,其中hssf xssf專案 http poi.apache.org spreadsheet index.html 用來實現excel讀寫的.public st...

POI 操作 EXCEL檔案

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

關於POI操作Excel

1.先導入jar包。poi 3.8.jar 不同版本操作的excel格式不同,xls和xlsx hssfworkbook,操作xls格式的excel xssfworkbook,操作xlsx格式的excel 最簡單的方法 test 測試excel.xls 2下面是 的方法 迴圈讀取sheet中的row...