关于EXECL导出的问题
在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是空表格,还有哪里要加代码吗???谢谢!!!
kao,demo一个个看下来,PersonEntity也要添加,版主啊,文档啊,指南啊,现在很多实现很多东西要靠读代码,要了我的命了:'( cian 发表于 2013-5-12 15:04 static/image/common/back.gif
kao,demo一个个看下来,PersonEntity也要添加,版主啊,文档啊,指南啊,现在很多实现很多东西要靠读代码, ...
目前已经有了在线文档了,你多看看
页:
[1]