hssfsheet sheet = workbook.createsheet("sheetname"); //建立sheet
sheet.setverticallycenter(true);
//下面樣式可作為匯出左右分欄的**模板
sheet.setcolumnwidth((short) 0, (short) 2600);// 設定列寬
sheet.setcolumnwidth((short) 1, (short) 2400);
sheet.setcolumnwidth((short) 2, (short) 2300);
sheet.setcolumnwidth((short) 3, (short) 1600);
sheet.setcolumnwidth((short) 4, (short) 1800);
sheet.setcolumnwidth((short) 5, (short) 1000);// 空列設定小一些
sheet.setcolumnwidth((short) 6, (short) 2600);// 設定列寬
sheet.setcolumnwidth((short) 7, (short) 2400);
sheet.setcolumnwidth((short) 8, (short) 2300);
sheet.setcolumnwidth((short) 9, (short) 1600);
sheet.setcolumnwidth((short) 10, (short) 1800);
hssfcellstyle cellstyle = (hssfcellstyle) workbook.createcellstyle();// 設定表頭樣式
cellstyle.setalignment(hssfcellstyle.align_center);// 設定居中
hssfcellstyle headerstyle = (hssfcellstyle) workbook .createcellstyle();// 建立標題樣式
headerstyle.setverticalalignment(hssfcellstyle.vertical_center); //設定垂直居中
headerstyle.setalignment(hssfcellstyle.align_center); //設定水平居中
hssffont headerfont = (hssffont) workbook.createfont(); //建立字型樣式
headerfont.setboldweight(hssffont.boldweight_bold); // 字型加粗
headerfont.setfontname("times new roman"); //設定字型型別
headerfont.setfontheightinpoints((short) 8); //設定字型大小
headerstyle.setfont(headerfont); //為標題樣式設定字型樣式
hssfcellstyle headerstyle1 = (hssfcellstyle) workbook .createcellstyle();// 建立標題樣式1
headerstyle1.setverticalalignment(hssfcellstyle.vertical_center);
headerstyle1.setalignment(hssfcellstyle.align_center);
hssffont headerfont1 = (hssffont) workbook.createfont();
headerfont1.setboldweight(hssffont.boldweight_bold);// 字型加粗
headerfont1.setfontname("times new roman");
headerfont1.setfontheightinpoints((short) 8);
headerstyle1.setfont(headerfont1);
hssfcellstyle headerstyle2 = (hssfcellstyle) workbook .createcellstyle();// 建立標題樣式2
headerstyle2.setverticalalignment(hssfcellstyle.vertical_center);
headerstyle2.setalignment(hssfcellstyle.align_center);
hssffont headerfont2 = (hssffont) workbook.createfont();
headerfont2.setboldweight(hssffont.boldweight_bold);// 字型加粗
headerfont2.setfontname("times new roman");
headerfont2.setfontheightinpoints((short) 8);
headerstyle2.setfont(headerfont2);
headerstyle2.setborderbottom(hssfcellstyle.border_thin); // 下邊框
headerstyle2.setborderleft(hssfcellstyle.border_thin);// 左邊框
headerstyle2.setbordertop(hssfcellstyle.border_thin);// 上邊框
headerstyle2.setborderright(hssfcellstyle.border_thin);// 右邊框
hssfcellstyle cell_style = (hssfcellstyle) workbook .createcellstyle();// 設定字型樣式
cell_style.setalignment(hssfcellstyle.align_center);
cell_style.setverticalalignment(hssfcellstyle.vertical_center);// 垂直對齊居中
cell_style.setwraptext(true); // 設定為自動換行
hssffont cell_font = (hssffont) workbook.createfont();
cell_font.setfontname("宋體");
cell_font.setfontheightinpoints((short) 8);
cell_style.setfont(cell_font);
cell_style.setborderbottom(hssfcellstyle.border_thin); // 下邊框
cell_style.setborderleft(hssfcellstyle.border_thin);// 左邊框
cell_style.setbordertop(hssfcellstyle.border_thin);// 上邊框
cell_style.setborderright(hssfcellstyle.border_thin);// 右邊框
hssfrow row = sheet.createrow((short)1); //建立行
hssfcell cell = row.createcell((short)1); //建立列
cell.setcellstyle(headerstyle2); //單元格引用樣式
poi excel匯出 案例
response.setheader connection close outputstream ouputstream response.getoutputstream 查詢匯出是按照專案匯出還是輔助段匯出 list list bonusservice.details string headers...
poi Excel 匯出工具類
public class myexcelutil if filename null listlistheader new arraylist 存放物件所有屬性 利用反射得到集合物件obj的所有屬性 包括父類和本類 公共和私有,所有屬性 class c list.get 0 getclass fiel...
關於npoi1 2 4 匯出excel樣式設定
首先.aspx頁面引用 其次 npoi public class excelgameresult 輸出檔案到瀏覽器 excel文件流 http上下文 檔名 datatable轉換成excel文件流 public static memorystream rendertoexcel datatable ...