importorg.Apache.poi.ss.usermodel.workbook; //部署方法所依赖的package包/类
//*
* excel下载
*/
@ request mapping (value=' download ' ) ) ) ) ) ) )。) )。) ) )。)
公共语音下载(httpservletrequestrequest,HttpServletResponse response ) throws Exception {
Workbook wb=null;
try {
logger.info (reportviewcontroller.download start );
//==========================数据
List datas=Lists.newArrayList (;
Map data0=Maps.newHashMap (;
DATA0.put(date,) 2017-01-01 );
数据0.put (date 1,2017-01-01 );
Map data1=Maps.newHashMap (;
data1.put(shoujiDai ),) 100 );
data1.put(daxueDai ),) 100 );
data1.put(ZiranDai ),) 100 );
DATA0.put(zidonghebishu ),data1 );
datas.add(data0;
//=======================================================================================
设定excel模板
maptemplateparams=maps.new hashmap (;
xstransformertransformer=newxlstransformer (;
WB=transformer.transform xls (app.class.getresourceasstream ) (/xls/excel.xlsx )、templateParams );
sheetbillinfosheet=WB.get sheet (sheet1);
设置excel演示配置
excelexportsettingexcelexportsetting=newexcelexportsetting ();
listcelllist=lists.new ArrayList (;
//1行数据的第1列
Celllist.add(newexcelmergecell )、“日期”和“日期”);
Celllist.add(newexcelmergecell ('第1天',' date1' ) );
//第一行数据中第二列合并单元格的
excelmergecellexcelmergecell=newexcelmergecell ("自动核数"、" zidonghebishu "、
Arrays.aslist(newexcelcell )、"大学信贷"、" daxuedai " )、
手机信用,(shoujidai ) )、
new ExcelCell ('自然信用',' zirandai ' ) )
Celllist.add(excelmergecell;
excelexportsetting.setheader row (cell list ); //设置页眉
excelexportsetting.set datalist (datas; //设定数据
写入excel
excelpoihelp.poiwrite(WB,billInfoSheet,excelExportSetting );
写入响应
String outFile='outputFile.xls ';
response.reset (;
response.add header (' content-disposition ',' attachment; filename=' new string (outfile.getbytes () );
outputstreamtoclient=newbufferedoutputstream (response.get output stream () );
response.set content type (application/vnd.ms-excel; charset=utf-8 ';
WB.write(toclient );
}catch(exceptione ) {
e .打印任务跟踪(;
} finally {
wb.close (;
}
}