?? 导出Excel集合
public void exportAll() { if(getTemplateName()!=null){ String templateName=getTemplateName(); String sortstr=FacesUtils.getValueInHashtableOfSession("sortstr").toString(); String hql=FacesUtils.getValueInHashtableOfSession("hql").toString()+sortstr; Map map=(Map)FacesUtils.getValueInHashtableOfSession("map"); List list = this.getService().getPageData(hql, map); Map beans=new HashMap(); beans.put("list", list); String filename=templateName+Tools.getNowTime()+".xls"; exportExcel(beans, templateName+".xls", filename); //日志 String message=templateName+"报表导出"; saveOpinfo(message); } } public void exportExcel(Map beans,String templateName,String filename) { try { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename=\"" + filename); ServletOutputStream outStream = response.getOutputStream(); ExcelUtils.exportExcel(beans, this.getText("template.path") + System.getProperty("file.separator") + templateName, outStream); response.getOutputStream().flush(); response.getOutputStream().close(); outStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } import net.sf.jxls.transformer.XLSTransformer; public static void exportExcel(Map beans, String templateName, OutputStream out) { XLSTransformer transformer = new XLSTransformer(); try { FileInputStream fis=new FileInputStream(templateName); transformer.transformXLS(fis, beans).write(out); fis.close(); } catch (ParsePropertyException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (InvalidFormatException e) { e.printStackTrace(); } }
?