日期:2014-05-16  浏览次数:20344 次

关于jsp页面导出excel的问题

使用jxl的话可以参考如下代码
在action中加入
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-disposition", "attachment; filename=" + "test.xls");
OutputStream os = response.getOutputStream();
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);
。。。。。
wwb.write();
wwb.close();
使用poi的话参考
response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-disposition", "attachment; filename=" + "test.xls");
OutputStream os = response.getOutputStream();
HSSFWorkbook workBook = new HSSFWorkbook();
workBook.write(os);
os.flush();
os.close();