java导出excel核心代码

来源:互联网 发布:怎样制作淘宝网页 编辑:程序博客网 时间:2024/06/07 06:34
     WritableWorkbook wbook = null;     WritableSheet sheet = null;     OutputStream os = null;     try {       response.reset();          //生成文件名       response.setHeader("Content-disposition", "attachment; filename="           + new String("错误信息".getBytes("GB2312"), "ISO8859-1")           + ".xls");       response.setContentType("application/msexcel");       os = response.getOutputStream();       wbook = Workbook.createWorkbook(os);       sheet = wbook.createSheet("信息", 0);       int row = 0;       //填写表头       setSheetTitle(sheet, row);       //遍历map,填充数据       setSheetData(sheet, map, row);       wbook.write();       os.flush();     } catch (Exception e) {       //自己处理     }finally {         try {//切记,此处一定要关闭流,否则你会下载一个空文件          if (wbook != null)              wbook.close();          if (os != null)              os.close();         } catch (IOException e) {            e.printStackTrace();         } catch (WriteException e) {            e.printStackTrace();      }  }
0 0