jsp 导出excel

来源:互联网 发布:陕西和泰单片机 编辑:程序博客网 时间:2024/04/30 19:43
@ResponseBody@RequestMapping(produces = "text/html;charset=UTF-8", value="/download", method=RequestMethod.GET)public String doDownload(HttpServletResponse response){Map<String, String> map = new HashMap<String,String>();String[] header={"联系方式","姓名","状态"};List<Phone> list = new ArrayList<Phone>();for (int i = 0; i < 20; i++) {Phone phone = new Phone();phone.setName("name"+i);phone.setPhone("1343299477"+i);phone.setStatus(UserStatus.FAILURE);list.add(phone);}Workbook wb =  WriteExcelUtil.createWorkbook(list,header);OutputStream out = null;try {out = response.getOutputStream();String showFileName = "MobileList.xls";response.addHeader("Content-disposition","attachment; filename=\"" + showFileName + "\"");response.setContentType("text/html;charset=UTF-8");wb.write(out);} catch (IOException e) {e.printStackTrace();}finally {//关闭流try {out.close();} catch (IOException e) {e.printStackTrace();}}return "";}



0 0