1. 程式人生 > >如何將table表中的資料匯出excel表

如何將table表中的資料匯出excel表

所用技術:Mybatis+Springmvc+Spring 

例子:

@RequestMapping(value = "/sbExport")
	 public void sbcscxInquiryExport(SbOverTime sbOverTime,HttpServletRequest request, HttpServletResponse response) throws IOException{
		Page<SbOverTime> page = new Page<SbOverTime>(request);
		page.setPageNo(1);
		page.setPageSize(Constants.Max_ExportNum);
		sbOverTimeService.getSbOverTime(page);
		List<SbOverTime> list = page.getResults();
		if(list != null && list.size() > 0){
			 String path = page.getParams().get("fileTitle").toString();
				response.setContentType("application/x-msdownload");
				response.setHeader("content-disposition", "attachment; filename="+new String(path.getBytes("gb2312"), "ISO8859-1" ) +".xls");
				response.setCharacterEncoding("utf-8");
				OutputStream out = response.getOutputStream();
				ExpExcelUtil<SbOverTime> ex = new ExpExcelUtil<SbOverTime>();
				ex.exportExcel(path,page.getParams(), list, out);
				out.close();
		 }
	 }