jxl 导出excel 无法弹出下载对话框

龙的传人1988 2014-02-25 02:08:29
以下是导出Excel的代码。
在tomcat服务器上导出是正常的,可以弹出对话框。
但在Jboss服务器上却不行,请高手回答一下是什么原因。
个人猜测问题出在response 里,但不知道具体怎么改



public static boolean exportToExcel(String tableHead,String sheetName,String exportFilename,ArrayList<ArrayList<String>> list,HttpServletResponse response) throws WriteException{
OutputStream os=null;
try {
os = response.getOutputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
WritableWorkbook wwb=null;
WritableSheet ws=null;
try {
response.setHeader("Content-disposition", new String(("attachment; filename="+exportFilename).getBytes("GBK"),"ISO-8859-1"));
response.setContentType("application/msexcel");
//创建Excel
wwb = Workbook.createWorkbook(os);
//创建Sheet
ws=wwb.createSheet(sheetName, 0);
//设置默认列宽
ws.getSettings().setDefaultColumnWidth(15);

//创建表头
WritableFont wfc = new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
WritableCellFormat wcfFC = new WritableCellFormat(wfc);
wcfFC.setAlignment(Alignment.CENTRE);
Label lable = null;
if(tableHead.indexOf(",")>=0){
String[] heads = tableHead.split(",");
for(int i=0;i<heads.length;i++){
lable = new Label(i,0,heads[i],wcfFC);
ws.addCell(lable);
}
}
//创建表单元
for(int i=0;i<list.size();i++){
ArrayList<String> rows = list.get(i);
for(int j=0;j<rows.size();j++){
lable = new Label(j, i+1, rows.get(j));
ws.addCell(lable);
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
finally{
try {
if(wwb != null){
wwb.write();
wwb.close();
}
if(os != null){
os.close();
}
wwb = null;
os = null;
} catch (IOException e) {
e.printStackTrace();
}
}
return true;

}
...全文
49 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧