這個是是在別人的框架上面改造的,做的複雜組合**的匯出
@requirespermissions("business:type:export")
@responsebody
public ajaxresult export(cardtype cardtype)
listlist = cardtypeservice.selectcardtypeandtblorglinklist(cardtype);
for(cardtype cardtypeinfo : list)
//建立乙個工作簿
hssfworkbook wb = new hssfworkbook();
string sheetname = "type";
//建立乙個工作表
hssfsheet sheet = wb.createsheet(sheetname);
//建立一行,行的索引是從0開始
hssfrow row = null;
//建立內容體的單元格的樣式
hssfcellstyle style_content = wb.createcellstyle();
style_content.setborderbottom(borderstyle.thin);//下邊框
style_content.setbordertop(borderstyle.thin);//上邊框
style_content.setborderleft(borderstyle.thin);//左邊框
style_content.setborderright(borderstyle.thin);//右邊框
//對齊方式:水平居中
style_content.setalignment(horizontalalignment.center);
//垂直居中
style_content.setverticalalignment(verticalalignment.center);
//建立內容樣式的字型
hssffont font_content = wb.createfont();
//設定字型名稱,相當選中哪種字元
font_content.setfontname("宋體");
//設定字型的大小
font_content.setfontheightinpoints((short)11);
style_content.setfont(font_content);
//表頭標題樣式
hssfcellstyle style_title = wb.createcellstyle();
// cellstyle style_title = wb.createcellstyle();
style_title.setalignment(horizontalalignment.center);
style_title.setverticalalignment(verticalalignment.center);
style_title.setborderbottom(borderstyle.thin);//下邊框
style_title.setbordertop(borderstyle.thin);//上邊框
style_title.setborderleft(borderstyle.thin);//左邊框
style_title.setborderright(borderstyle.thin);//右邊框
//設定表頭背景顏色
//設定填充
style_title.setfillpattern(fillpatterntype.solid_foreground);
//設定填充顏色
style_title.setfillforegroundcolor(indexedcolors.grey_50_percent.getindex());
//設定表頭字型樣式
hssffont style_font = wb.createfont();
style_font.setfontname("黑體");
style_font.setfontheightinpoints((short)10);
//加粗
style_font.setbold(true);
style_title.setfont(style_font);
for(int i = 0; i < 2; i++)
} //合併單元格
sheet.addmergedregion(new cellrangeaddress(0, 1, 0, 0));
sheet.addmergedregion(new cellrangeaddress(0, 1, 1, 1));
sheet.addmergedregion(new cellrangeaddress(0, 1, 2, 2));
sheet.addmergedregion(new cellrangeaddress(0, 0, 3, 9));
sheet.addmergedregion(new cellrangeaddress(0, 0, 10, 13));
sheet.addmergedregion(new cellrangeaddress(0, 0, 14, 16));
for(int i = 2; i < list.size() + 2; i++)
} //給excle設定單元格值 getrow(0) : 第一行 getcell(0) 第一列
sheet.getrow(0).getcell(0).setcellvalue("序號");
sheet.getrow(0).getcell(1).setcellvalue("機構名稱");
sheet.getrow(0).getcell(2).setcellvalue("卡種類");
sheet.getrow(0).getcell(3).setcellvalue("當前");
sheet.getrow(0).getcell(10).setcellvalue("本期");
sheet.getrow(0).getcell(14).setcellvalue("序號");
sheet.getrow(1).getcell(3).setcellvalue("主卡數");
sheet.getrow(1).getcell(4).setcellvalue("附卡數");
sheet.getrow(1).getcell(5).setcellvalue("活卡數");
sheet.getrow(1).getcell(6).setcellvalue("客戶數");
sheet.getrow(1).getcell(7).setcellvalue("睡眠數(張)");
sheet.getrow(1).getcell(8).setcellvalue("睡眠數(戶數)");
sheet.getrow(1).getcell(9).setcellvalue("存款餘額");
sheet.getrow(1).getcell(10).setcellvalue("發卡數(張)");
sheet.getrow(1).getcell(11).setcellvalue("正常換卡數(張)");
sheet.getrow(1).getcell(12).setcellvalue("掛失補卡數(張)");
sheet.getrow(1).getcell(13).setcellvalue("銷卡數(張)");
sheet.getrow(1).getcell(14).setcellvalue("發卡數(張)");
sheet.getrow(1).getcell(15).setcellvalue("銷卡數(張)");
sheet.getrow(1).getcell(16).setcellvalue("啟用數(張)");
for(int i = 0; i < list.size(); i++)
sheet.getrow(0).setheight((short)500);
sheet.getrow(1).setheight((short)500);
//設定列寬
for(int i = 0; i < 17; i++)
outputstream out = null;
try
catch (exception e)
", e.getmessage());
}finally
catch (ioexception e1)
}if (out != null)
catch (ioexception e1)}}
}/**
* 編碼檔名
*/public string encodingfilename(string filename)
/***
* @param filename 檔名稱
*/public string getabsolutefile(string filename)
return downloadpath;
}
Poi 匯出帶複雜表頭多個sheet的內容
目錄 poi 匯出帶複雜表頭多個sheet的內容 contrller service 匯出工具類 excelexportutil 匯出類 poiexcelexporter 測試用postman 結果 總結 知道了如何匯出單個sheet複雜表頭的內容?如何匯出多個的呢?結和匯出簡單表頭多個sheet的...
POI的匯入匯出
匯入測試 匯入的模板一定要按照格式準備,固定每列的內容 created by hp on 2018 9 18.public class poiimport 匯出測試 created by hp on 2018 9 18.public class poiexport poi匯入用的是jquery的oc...
簡單的poi匯出
org.apache.poi poi ooxml 3.17 org.apache.poi poi3.17 package com.bw.entity public class user public void setuid integer uid public string getuname pub...