解析指定頁面,得到pdf文件的地址,用URL來取回pdf的輸入流,然后寫到本地文件。
在蟠龍等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計(jì)、網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),全網(wǎng)整合營(yíng)銷推廣,外貿(mào)網(wǎng)站建設(shè),蟠龍網(wǎng)站建設(shè)費(fèi)用合理。
最好是將模版定義為格式話好的文件,數(shù)據(jù)庫里面存模版的名字,這樣通過關(guān)鍵判斷使用什么模版,希望能幫到你
controller層關(guān)鍵代碼:
@RequestMapping(value?=?"/excel")
public?ModelAndView?exportExcel()?throws?Exception?{
ModelAndView?mv?=?new?ModelAndView();
PageData?pd?=?new?PageData();
pd?=?this.getPageData();
MapString,?Object?dataMap?=?new?HashMapString,?Object();
ListString?titles?=?new?ArrayListString();
titles.add("辦事處");?//?1
titles.add("當(dāng)日新增掃碼商戶(個(gè))");?//?2
titles.add("當(dāng)日交易筆數(shù)(筆)");?//?3
titles.add("當(dāng)日交易金額");?//?4
titles.add("當(dāng)日收益");?//?5
titles.add("累計(jì)新增掃碼商戶(個(gè))");?//?6
titles.add("累計(jì)交易筆數(shù)(筆)");?//?7
titles.add("累計(jì)交易金額");?//?8
titles.add("累計(jì)收益");?//?9
dataMap.put("titles",?titles);
Page?page?=?new?Page();
page.setPd(pd);
ListPageData?varOList?=?agencyService.list(page);
ListPageData?varList?=?new?ArrayListPageData();
for?(int?i?=?0;?i??varOList.size();?i++)?{
PageData?vpd?=?new?PageData();
vpd.put("var1",?varOList.get(i).get("AGENCYNAME").toString());?//?1
vpd.put("var2",?varOList.get(i).get("TODAYINSTALL").toString());?//?2
vpd.put("var3",?varOList.get(i).get("TODAYTRANS").toString());?//?3
vpd.put("var4",?varOList.get(i).get("TODAYPRICE").toString());?//?4
vpd.put("var5",?varOList.get(i).get("TODAYPAYMENT").toString());?//?5
vpd.put("var6",?varOList.get(i).get("TOTALINSTALL").toString());?//?6
vpd.put("var7",?varOList.get(i).get("TOTALTRANS").toString());?//?7
vpd.put("var8",?varOList.get(i).get("TOTALPRICE").toString());?//?8
vpd.put("var9",?varOList.get(i).get("TOTALPAYMENT").toString());?//?9
varList.add(vpd);
}
dataMap.put("varList",?varList);
ObjectExcelView?erv?=?new?ObjectExcelView();
mv?=?new?ModelAndView(erv,?dataMap);
return?mv;
}
POI生成EXCEL關(guān)鍵代碼:
public?class?ObjectExcelView?extends?AbstractExcelView{
@SuppressWarnings("deprecation")
@Override
protected?void?buildExcelDocument(MapString,?Object?model,
HSSFWorkbook?workbook,?HttpServletRequest?request,
HttpServletResponse?response)?throws?Exception?{
//?TODO?Auto-generated?method?stub
Date?date?=?new?Date();
String?filename?=?Tools.date2Str(date,?"yyyyMMddHHmmss");
HSSFSheet?sheet;
HSSFCell?cell;
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition",?"attachment;filename="+filename+".xls");
sheet?=?workbook.createSheet("sheet1");
ListString?titles?=?(ListString)?model.get("titles");
int?len?=?titles.size();
HSSFCellStyle?headerStyle?=?workbook.createCellStyle();?//標(biāo)題樣式
headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
HSSFFont?headerFont?=?workbook.createFont(); //標(biāo)題字體
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerFont.setFontHeightInPoints((short)11);
headerStyle.setFont(headerFont);
short?width?=?20,height=25*20;
sheet.setDefaultColumnWidth(width);
for(int?i=0;?ilen;?i++){?//設(shè)置標(biāo)題
String?title?=?titles.get(i);
cell?=?getCell(sheet,?0,?i);
cell.setCellStyle(headerStyle);
setText(cell,title);
}
sheet.getRow(0).setHeight(height);
HSSFCellStyle?contentStyle?=?workbook.createCellStyle();?//內(nèi)容樣式
contentStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
ListPageData?varList?=?(ListPageData)?model.get("varList");
int?varCount?=?varList.size();
for(int?i=0;?ivarCount;?i++){
PageData?vpd?=?varList.get(i);
for(int?j=0;jlen;j++){
String?varstr?=?vpd.getString("var"+(j+1))?!=?null???vpd.getString("var"+(j+1))?:?"";
cell?=?getCell(sheet,?i+1,?j);
cell.setCellStyle(contentStyle);
setText(cell,varstr);
}
}
}
}