java代码实现模板下载 java编程模板

java项目中怎么实现模板管理?最好是将模版定义为格式话好的文件,数据库里面存模版的名字,这样通过关键判断使用什么模版,希望能帮到你
java怎么实现下载指定网页中包含的pdf文件 。求代码?解析指定页面,得到pdf文件的地址,用URL来取回pdf的输入流 , 然后写到本地文件 。
java项目中怎么实现jsp页面Excel模板下载并弹框 。controller层关键代码:
@RequestMapping(value = "https://www.04ip.com/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; ivarOList.size(); i) {
PageData vpd = new PageData();
vpd.put("var1", varOList.get(i).get("AGENCYNAME").toString()); // 1
【java代码实现模板下载 java编程模板】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编程模板的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读