java代码实现模板下载 java代码大全手册
java怎么实现下载指定网页中包含的pdf文件。 求代码?
解析指定页面,得到pdf文件的地址,用URL来取回pdf的输入流,然后写到本地文件。
在蟠龙等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计、网站制作 网站设计制作按需网站开发,公司网站建设,企业网站建设,成都品牌网站建设,全网整合营销推广,外贸网站建设,蟠龙网站建设费用合理。
java项目中怎么实现模板管理?
最好是将模版定义为格式话好的文件,数据库里面存模版的名字,这样通过关键判断使用什么模版,希望能帮到你
java项目中怎么实现jsp页面Excel模板下载并弹框。
controller层关键代码:
@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("当日新增扫码商户(个)"); // 2
titles.add("当日交易笔数(笔)"); // 3
titles.add("当日交易金额"); // 4
titles.add("当日收益"); // 5
titles.add("累计新增扫码商户(个)"); // 6
titles.add("累计交易笔数(笔)"); // 7
titles.add("累计交易金额"); // 8
titles.add("累计收益"); // 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关键代码:
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(); //标题样式
headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
HSSFFont headerFont = workbook.createFont(); //标题字体
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++){ //设置标题
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(); //内容样式
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);
}
}
}
}
分享标题:java代码实现模板下载 java代码大全手册
本文路径:http://cdiso.cn/article/ddopcjc.html