java excel导出 页面消失 后台不报错 请大神们指点

private void exportShipmentItemListDetail(List<ShipmentItemValue> list,HttpServletResponse response) throws UnsupportedEncodingException {

response.setContentType("application/vnd.ms-excel;charset=UTF-8");
String filename = new String("出入库单据详情列表.xls".getBytes("gb2312"),"ISO8859-1");
response.addHeader("Content-Disposition", "filename=" + filename);

WritableWorkbook wwb = null;
try {
OutputStream os=response.getOutputStream();

//创建Excel工作表
wwb = Workbook.createWorkbook(os);

//创建sheet
WritableSheet ws = wwb.createSheet("出入库单据详情", 0);

//合并单元格(左列,左行,右列,右行)从第1行第1列到第2行第4列
ws.mergeCells(0, 0, 17, 1);
ShipmentItemValue shipmentItemValue=list.get(i);
if(shipmentItemValue!=null){
l = new Label(h++, i+4, shipmentItemValue.getSupplierName(), ExportUtils.getNormolCell());//第2行,第6列
ws.addCell(l);
l = new Label(h++, i+4, shipmentItemValue.getOutStore(), ExportUtils.getNormolCell());//第2行,第6列
ws.addCell(l);
l = new Label(h++, i+4, shipmentItemValue.getOutFacility(), ExportUtils.getNormolCell());//第2行,第6列
ws.addCell(l);
l = new Label(h++, i+4, shipmentItemValue.getInStore(), ExportUtils.getNormolCell());//第2行,第6列
ws.addCell(l);
}
}
wwb.write();
wwb.close();
os.flush();
os.close();
}

}
这是我写的导出代码 我DEBUG走到wwb.write();的时候页面就会显示这个
请大神指教

你这段代码应该大的方向没有错的。因为你给的代码不全,我把你的代码简化了(去掉传入的list参数,以及方法内未定义的变量)运行是没有问题的。

public void exportShipmentItemListDetail(HttpServletResponse response) throws UnsupportedEncodingException {
  response.setContentType("application/vnd.ms-excel;charset=UTF-8");
  String filename = new String("出入库单据详情列表.xls".getBytes("gb2312"),"ISO8859-1");
  response.addHeader("Content-Disposition", "filename=" + filename);
  WritableWorkbook wwb = null; 
  try {
   OutputStream os=response.getOutputStream();
   //创建Excel工作表
   wwb =  Workbook.createWorkbook(os);
   //创建sheet
   WritableSheet ws = wwb.createSheet("出入库单据详情", 0);
   //合并单元格(左列,左行,右列,右行)从第1行第1列到第2行第4列
   ws.mergeCells(0, 0, 17, 1);
   Label l = null;
   l = new Label(0, 0, "1", null);//第2行,第6列   
   ws.addCell(l);
   l = new Label(1, 1, "2", null);//第2行,第6列   
   ws.addCell(l);
   wwb.write();
   wwb.close();   
   os.flush();
   os.close();  
  }catch(Exception e){}//因为你用了try,所以要加catch,不然编译不通过
 }

这个样子我这边可以正常运行的。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-01-28
wwb.write(os);
相似回答