poi知識積累

2021-06-28 12:55:34 字數 3847 閱讀 5185

匯出需要的頭:response.setcontenttype("octets/stream;charset=utf-8");     (需要匯出的 型別都是可以在tomcat---conf下的web.xml中找到)

response.setheader("content-disposition","attachment;filename=a.xls");

如果不確定,最好是採取直接寫入,從上往下,或者從左往右寫.

獲取(cell)單元格中內容的方法:

//獲取行中的列

hssfrow datarow = sheet.getrow(i);

hssfcell datacell = datarow.getcell(0);

string firstcell = excelutil.readcell(datacell);

//readcell方法  待定

//數字保留幾位小數     string vald = string.format("%.5f", val);       (此處保留val的五位小數,其中val為double型別返回的是string型別)

1,合併單元格

sheet.addmergedregion(new region(0, (short) (celln + 1), 0,  (short) (celle + 1)));   四個引數分別代表

起始行,

起始列,

結束行,結束列.

2,一格格插入
public static void setcellvalue(hssfsheet sheet,int irow, int icolumn, string values,

hssfcellstyle style) throws exception catch (exception e)

}

3,建立(cell)單元格的格式

先獲取工作薄物件:

hssfworkbook wb = new hssfworkbook();

hssfsheet sheet = wb.createsheet();

hssfcellstyle setborder = wb.createcellstyle();

一、設定背景色:

setborder.setfillforegroundcolor((short) 13);// 設定背景色

setborder.setfillpattern(hssfcellstyle.solid_foreground);

二、設定邊框:

setborder.setborderbottom(hssfcellstyle.border_thin); //下邊框

setborder.setborderleft(hssfcellstyle.border_thin);//左邊框

setborder.setbordertop(hssfcellstyle.border_thin);//上邊框

setborder.setborderright(hssfcellstyle.border_thin);//右邊框

三、設定居中:

setborder.setalignment(hssfcellstyle.align_center); // 居中

四、設定字型:

hssffont font = wb.createfont();

font.setfontname("黑體");

font.setfontheightinpoints((short) 16);//設定字型大小

hssffont font2 = wb.createfont();

font2.setfontname("仿宋_gb2312");

font2.setboldweight(hssffont.boldweight_bold);//粗體顯示

font2.setfontheightinpoints((short) 12);

setborder.setfont(font);//選擇需要用到的字型格式

五、設定列寬:

sheet.setcolumnwidth(0, 3766); //第乙個引數代表列id(從0開始),第2個引數代表寬度值  參考 :"2012-08-10"的寬度為2500

六、設定自動換行:

setborder.setwraptext(true);//設定自動換行

七 、沒有模板輸出excel

response.setcontenttype("octets/stream;charset=utf-8");

string str=new string("車身.xls".getbytes(),"iso-8859-1");

system.out.println(str);

response.setheader("content-disposition","attachment;filename="+str);

outputstream out =response.getoutputstream();

hssfworkbook work=new hssfworkbook();

hssfcellstyle style=work.createcellstyle();

style.setalignment(hssfcellstyle.align_center);

style.setfillbackgroundcolor((short)23);

hssffont font=work.createfont();

font.setcolor(hssffont.color_red);

style.setfont(font);

hssfsheet sheet1=work.createsheet("車身");

sheet1.setdefaultcolumnwidth(15);

八.帶模板輸出excel

//獲取模板

public hssfworkbook   gettemplate(string filepath) catch (exception e)

return wb;

}// 匯出

hssfworkbook work = this.gettemplate(request.getrealpath("/")+"resource/excel/dpmvalue.xls");

hssfsheet sheet=work.getsheetat(0);

hssfcellstyle style=work.createcellstyle();

style.setalignment(hssfcellstyle.align_center);

hssffont font=work.createfont();

font.setcolor(hssffont.color_red);

style.setfont(font);

excelutil.setcellvalue(sheet, 0, 0, "淨現值和moc(%)演變 evolution de van", style);

//setcellvalue 方法

public static void setcellvalue(hssfsheet sheet,int irow, int icolumn, string values,

hssfcellstyle style) throws exception

hssfcell cell = row.getcell((short) icolumn);

if (cell == null)

cell.setcelltype(hssfcell.cell_type_string);

if (values == null)

cell.setcellvalue(values);

cell.setcellstyle(style);

} catch (exception e) }

知識的積累

最初認識darwin 的時候,我還是個沒畢業的新手。那時,我在公司做畢業設計,題目就是用c 對部門內已有的一套c的庫進行封裝。那套庫就是darwin開發的,這次封裝工作也是在他的領導之下進行的。當時,我對c 有著說不清的好感,心裡認定那是成為高手的必經之路,因此很樂於參加到這個工作之中。darwin...

Machine Vision知識積累

注.本部分 以下鏈結 工業相機與工業鏡頭 光源 感測器 影象採集卡 pc平台 視覺處理軟體 控制單元 漢王mvstudio visionpro cvl 康耐視 evision 比利時euresys公司 labview vision mil機器視覺庫 加拿大matrox image library h...

小知識積累

1.有關 和printf的應用 printf是從右向左壓棧 printf d,d n ptr,ptr 先是 ptr 從右至左,所以輸出的兩個值是一樣的 ptr 123 那麼先是 ptr 123 然後是ptr 2.float a 1.0f int a的作用是將浮點數字址開始的sizeof int 個位...