上模板:
JS:
function exportQianShu() { var data = { }; onloading();//开启加载效果 urls = rootPath+"a/ordermanage/GSPO005/exportQianShu"; $.ajax({ url:urls, type:'post', data:data, dataType:'xml', success:function(data,textStatus){ populateList(data,textStatus); }, error:function(){ $.messager.alert("提示信息",'系统出错','warning'); } }); }
Controller
@RequestMapping("exportQianShu") public void exportQianShu(VSpPOrderArrivalEntity entity,HttpServletRequest request,HttpServletResponse response,Model model) throws Exception{ String resultCode = "1"; //1成功,2失败 String message = "导出成功"; //信息 String url = "url"; //种子文件 url = gSPO005Service.exportQianShu(entity,request,response); PrintWriter out = null; response.setContentType("text/xml; charset=utf-8"); StringBuffer str = new StringBuffer(); str.append("rn"); str.append(""); str.append(" "); try { out = response.getWriter(); out.print(str.toString()); } catch (IOException e) { logger.error("机能:{},导出文件出现异常:",JobIds.GSPO014); logger.error(e.getMessage()); LogPrinter.printStackTrace(e); } logger.debug("机能:{},文件响应成功!",JobIds.GSPO014); }"); str.append(resultCode); str.append(" "); str.append(""); str.append(message); str.append(" "); str.append(""); str.append(url); str.append(" "); str.append("
Service
public String exportQianShu(VSpPOrderArrivalEntity entity, HttpServletRequest request, HttpServletResponse response) throws Exception { //得到用户登录名 String username = UserUtils.getUser().getName(); String fileName = username+"-一键导欠数.xls"; String nowTime = DateUtils.getDate("yyyyMMddHHmmss"); //创建文件路径 String folder=request.getSession().getServletContext().getRealPath("/")+"export/excel/"+nowTime; // String folder = SystemPath.getSysPath()+"export/excel/"+nowTime; String outputfile = folder+"/"+fileName; File foldertemp = new File(folder); if (!foldertemp.exists()) { foldertemp.mkdirs(); } // execl模板路径 String inputFile = SystemPath.getSysPath() + "export/model/GSPO005exportmodel.xls"; entity.setOrderFlag("0"); entity.setRemark("一键导欠数"); // 查询导出数据 Listlist = gSPO005Dao.findList(entity); if(list.size()>0){ ReportEnginer enginer = new ReportEnginer(); Map context = new HashMap (); //生成模板模板数据 // result=this.setQingDan(list, context); context.put("detailList", list); enginer.excute(inputFile, context, outputfile); } return "export/excel/"+nowTime+"/"+fileName; }
导出效果图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)