JSP页面表单数据导出到excel表格
1 <% 2 String excelname="test.xls"; //定义excel文件名 3 response.setContentType( "application/vnd.ms-excel;charset=utf-8"); 4 response.setHeader("content-disposition","attachment; filename=" +excelname ); 5 %>
在导出按钮跳转的页面的头上加此段落,同时再导出按钮跳转的页面需要插入相应的list结果。
1 <div class="zb_tabinfo"> 2 <table class="tableclick" id="waitTable"> 3 <thead> 4 <tr> 5 .. 15 </tr> 16 </thead> 17 <tbody> 18 <c:forEach items="${list}" var="reportrecord"> 19 .... 31 </c:forEach> 32 </tbody> 33 </table> 34</div>
然后就可以了
2017年9月4日 17:26:07
刚改了需求,要求导出为word,去网上查了一下,原来只需要改一下头就可以了。
1 <% 2 String excelname="test.doc"; //定义excel文件名 3 response.setContentType( "application/vnd.ms-word;charset=utf-8"); 4 response.setHeader("content-disposition","attachment; filename=" +excelname ); 5 %>
另:附上相关资料
1 contentType的值 2 ".dwf": "Application/x-dwf"; 3 ".pdf": "Application/pdf"; 4 ".doc": "Application/vnd.ms-word"; 5 ".ppt": "Application/vnd.ms-powerpoint"; 6 ".pps": "Application/vnd.ms-powerpoint"; 7 ".xls": "Application/vnd.ms-excel"; 8 default: "Application/octet-stream";
参考 http://blog.csdn.net/wlbing0625/article/details/7802475
好好学习,天天向上,仅作自己工作的记录与总结。如有谬误,幸勿哂笑。

浙公网安备 33010602011771号