java 通过模板导出excel文件

java 通过模板导出excel文件,第1张

java 通过模板导出excel文件

上模板:

 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("");
	str.append(resultCode);
	str.append("");
	str.append("");
	str.append(message);
	str.append("");
	str.append("");
	str.append(url);
	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);
	
}

 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("一键导欠数");
		// 查询导出数据
		List list = 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;
	}

导出效果图:

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5676498.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存