|
在personList.jsp中添加:
<script type="text/javascript" charset="utf-8">
/*
* excel导出
*/
function exportXls() {
window.location.href="personController.do?exportXls";
}
</script>
和
<t:dgToolBar title="导出excel" ></t:dgToolBar>
在PersonController.java中添加:
@RequestMapping(params = "exportXls")
public void exportXls(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
// 生成提示信息,
response.setContentType("application/vnd.ms-excel");
String codedFileName = null;
OutputStream fOut = null;
try
{
// 进行转码,使其支持中文文件名
codedFileName = java.net.URLEncoder.encode("人员查询", "UTF-8");
response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
// 产生工作簿对象
HSSFWorkbook workbook = null ;
List<PersonEntity> persons = this.personService.loadAll(PersonEntity.class);
workbook = ExcelExportUtil.exportExcel("导出信息", PersonEntity.class, persons);
fOut = response.getOutputStream();
workbook.write(fOut);
}
catch (UnsupportedEncodingException e1)
{
}
catch (Exception e)
{
}
finally
{
try
{
fOut.flush();
fOut.close();
}
catch (IOException e)
{
}
}
}
但导出的EXCEL是空表格,还有哪里要加代码吗???谢谢!!!
|
|