Excel匯入匯出

2021-10-02 23:56:20 字數 2378 閱讀 4413

// 生成乙個樣式

hssfcellstyle style = workbook.

createcellstyle()

;// 設定這些樣式

style.

setalignment

(hssfcellstyle.align_center)

;//水平居中,hssfcellstyle.align_left居左

style.

setverticalalignment

(hssfcellstyle.vertical_center)

;//垂直居中

// 背景色

style.

setfillforegroundcolor

(hssfcolor.yellow.index)

;style.

setfillpattern

(hssfcellstyle.solid_foreground)

; style.

setfillbackgroundcolor

(hssfcolor.yellow.index)

;//背景色

// 設定邊框

style.

setborderbottom

(hssfcellstyle.border_thin)

;//下邊框

style.

setborderleft

(hssfcellstyle.border_thin)

;//左邊框

style.

setborderright

(hssfcellstyle.border_thin)

;//右邊框

style.

setbordertop

(hssfcellstyle.border_thin)

;//上邊框

// 自動換行

style.

setwraptext

(true);

//單元格內文字有換行的,設之後自動換行

// 生成乙個字型

hssffont font = workbook.

createfont()

;font.

setfontheightinpoints((

short)10

);//字型大小

font.

setcolor

(hssfcolor.red.index)

;//字型顏色

font.

setboldweight

(hssffont.boldweight_bold)

;//字型粗細

font.

setfontname

("宋體");

// 把字型 應用到當前樣式

style.

setfont

(font)

;//style設定好後,為cell設定樣式

hssfworkbook workbook =

newhssfworkbook()

;//建立乙個文件

hssfsheet sheet = workbook.

createsheet

("名稱");

//建立乙個sheet

hssfrow row = sheet.

createrow

(rownumber)

//建立乙個行號為rownumber的行

hssfcell cell = row.

createcell

(i)//建立列編號為i的格仔

cell.

setcellstyle

(style)

//cell為已有的單元格 //這裡,設定單元格格式

cell.

setcellvalue

(內容)

//單元格的內容

主要是sheet.addmergedregion(region)這個方法

sheet.

addmergedregion

(new

cellrangeaddress

(int firstrow,

int lastrow,

int firstcol,

int lastcol)

sheet頁的列數讀取區別
getphysicalnumberofcells 是獲取不為空的列個數。

getlastcellnum 獲取最後乙個有資料的列

這倆都是對行操作的

和easypoi相比更簡單方便,而且更省記憶體, easyexcel官網

excel匯入匯出

匯出 yii框架中 header content disposition attachment filename 123.xls arr connection createcommand select from recruit queryall array this db get recruit r...

EXCEL匯入匯出

系統管理員登入,系統下資源管理 分機號列表內容匯出 suppresswarnings rawtypes responsebody public jsonobject selectfenjihaoinxitongforexportbyparam requestparam value fenjihao ...

excel匯入匯出

匯出 匯出相對比較簡單在控制層的關鍵 為 string filename 成果資料 dateutils.getdate yyyymmddhhmmss xlsx listpersonneltitlelist personneltitleservice.findlist personneltitle n...