使用poi生成Excel文件

  1. public ActionForward action(ActionMapping mapping, ActionForm form,
  2.             HttpServletRequest request, HttpServletResponse response)
  3.             throws Exception {
  4.         response.setContentType("application/vnd.ms-excel");
  5.         response.addHeader("Content-Disposition""attachment;filename=xsmd");
  6.         HSSFWorkbook wb = new HSSFWorkbook();
  7.         HSSFSheet sheet = wb.createSheet("new sheet");
  8.         HSSFRow row = sheet.createRow(0);
  9.         HSSFCell cell = row.createCell((short0);
  10.         cell.setCellValue("id");
  11.         cell = row.createCell((short1);
  12.         cell.setCellValue("name");
  13.         cell = row.createCell((short2);
  14.         cell.setCellValue("age");
  15.         ServletOutputStream os = response.getOutputStream();
  16.         wb.write(os);
  17.         os.flush();
  18.         return null;
  19.     }

你可能感兴趣的:(使用poi生成Excel文件)