Excel的导出

来源:互联网 发布:同床异梦的人工智能 编辑:程序博客网 时间:2024/06/05 16:25
1.在html中添加iframe

<iframe id="exFrame" name="exFrame" width="0" height="0"></iframe>

2.向后台发送请求

function exportExcel(){var packForm = $("#sellStatForm");packForm.attr("target", "exFrame");//设置链接的target为iframepackForm.attr("action", "/zhaojin/sellstat/exportExcel");packForm.submit();packForm.removeAttr("target");}

3、首先要设置contentType

response().reset(); response().setContentType ( "application/ms-excel" ) ;response().addHeader("Content-Disposition", "attachment;filename=sellstat.xls");

4.建立好excel格式,导入数据后
OutputStream out=null;out= new BufferedOutputStream(response().getOutputStream());workbook.write(out);