部落格筆記161207(java操作execl)

2021-07-25 05:27:21 字數 1913 閱讀 5108

利用poi實現excel**的匯出(jar使用:poi-3.9.jar-匯出execl是2003版)

1,宣告乙個工作薄

hssfworkbook workbook = new hssfworkbook();

2,生成乙個**

hssfsheet sheet = workbook.createsheet("**名稱");

3,凍結行列

/*凍結行列(行或者列不隨滾動)

* 第乙個引數表示要凍結的列數;

第二個引數表示要凍結的行數,

第三個引數表示右邊區域可見的首列序號,從1開始計算;

第四個引數表示下邊區域可見的首行序號,也是從1開始計算

* */

sheet.createfreezepane( 0, 4, 0, 4 );//此處凍結前四行

4,生成乙個單元格樣式

hssfcellstyle cellstyle = workbook.createcellstyle();

cellstyle .setfillforegroundcolor(hssfcolor.white.index);//背景填充

cellstyle .setfillpattern(hssfcellstyle.solid_foreground);//圖案填充

cellstyle .setverticalalignment(hssfcellstyle.vertical_center);// 垂直居中

cellstyle .setalignment(hssfcellstyle.align_center);// 水平居中

4.1,生成乙個字型

hssffont font = workbook.createfont();

font.setcolor(hssfcolor.black.index);//字型顏色

font.setfontheightinpoints((short) 12);//字型大小

font.setboldweight(hssffont.boldweight_bold);//加粗處理

font.setfontname("宋體");//字型型別

4.2 把字型應用到當前的樣式

headstyle.setfont(font);

5,實現乙個單元格有多種樣式(字型樣式demo)

hssffont redfont = (hssffont) workbook.createfont();  

redfont.setcolor(hssfcolor.red.index);// 紅色 字型 

hssffont bluefont = (hssffont) workbook.createfont();  

redfont.setcolor(hssfcolor.blue.index);// 藍色字型 

//建立乙個單元格  

hssfcell celldemo =sheet .createcell(0);  

//建立富文字字串,內容為:redfont,bulefont  

hssfrichtextstring richstring = new hssfrichtextstring( "redfont,bulefont " );  

//將富文字字串設定到單元格中  

celldemo .setcellvalue( richstring );  

6,單元格合併

*第乙個引數:起始行號

*第二個引數:起始列號

*第三個引數:結束行號

*第四個引數:結束列號

*引數均是從0開始,包括前也包括後

region regiontitle = new region(0, (short) 0, 0, (short)8);

sheet.addmergedregion(regiontitle);// 第乙個行合併前9列

7,待續。。。。。。

java操作字串 CSDN部落格

title test class arrat description 該方法的主要作用 param 設定檔案 return 返回型別 void throws test public void test is equals else if str1.equals str2 else title tes...

java檔案讀取操作筆記

按行讀取 整體讀取 分行讀取 bufferedreader reader new bufferedreader new filereader file int file.length 1 標記 string l while l reader.readline null 回到起點 while l re...

《Java物件導向程式設計》學習筆記4 操作符簡介

1.注意 還能操作各種引用型別。而 除了可以操作包含boolean型別以外的基本資料型別外,還可以操作string型別。2.多數操作符都是從左到右運算的,但是賦值操作是從右到左。3.整型操作符在計算表示式時,若乙個操作元是long,那麼結果也是long,否則不管操作元是byte還是short cha...