SSH整合中如何将页面的数据导出Excel的文件???求指点!谢谢
再做一个HR系统的时候,需求要将页面的数据导出,是Excel文件的形式,请哪位高手指点!以前没这样做过!谢谢!!!
扣扣号: 403645933
------解决方案--------------------
function do_exl(){
ArrayList alllist= (ArrayList)request.getAttribute("alllist");
request.getSession().setAttribute("alllist",alllist);
ArrayList tlist= (ArrayList)request.getAttribute("tlist");
request.getSession().setAttribute("tlist",tlist);
request.getSession().setAttribute("type",type);
%>
location="<%=path%>/main/exl/exl.jsp";
}
打印界面exl.jsp
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
response.addHeader("Content-Disposition", "filename=userinfo.xls");
int i = 0;
ArrayList<Exl> item = (ArrayList<Exl>)request.getSession().getAttribute("alllist");
ArrayList<Type> tlist = (ArrayList<Type>)request.getSession().getAttribute("tlist");
%>
其他的都一样
------解决方案--------------------页面数据导出到excel?通过一个控制器把数据写入到一份exel然后在下载下来?
------解决方案--------------------用poi,我刚做了 很好用! 百度一下就可以了!!!
------解决方案--------------------用poi...记得导入poi的几个包。
Java code
response.setHeader("Content-Disposition", "attchment;filename=abc.xls");
HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(new HSSFRichTextString("xxxxxxxxxx"));
book.write(response.getOutputStream());