java批量数据导出excel,为什么老是只生成一个excel文件1、主类:for(intn=0;n
java批量数据导出excel,为什么老是只生成一个excel文件
1、主类:
for (int n = 0; n < sheetCnt; n++)
{
try
{
//调用
exportExcel(res);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
2.调用exportExcel(res);
public void exportExcel(HttpServletResponse res)
throws Exception
{
try
{
OutputStream os = null;
os = res.getOutputStream();
//下面一句是导出excel下载时的文件名
String fs = "";
fs = "明细查询";
//转成中文编码
fs = new String(fs.getBytes("gb2312"), "iso8859-1");
// 清空输出流
res.reset();
// 定义输出类型
res.setContentType("application/msexcel");
// 设定输出文件头
res.setHeader("Content-disposition", "attachment; filename=" + fs + ".xls");
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);
jxl.write.WritableSheet ws = wwb.createSheet("明细查询", 0);
// 标题字体大小
int charTitle = 10;
// 标题字体大小
int charNormal = 10;
.....
//写入Exel工作表
wwb.write();
//关闭Excel工作薄对象
wwb.close();
//关闭Excel输出流
os.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
展开