struts2 poi导出excel函数

 
 public String expExcelAudit() throws Exception {
  if(operationIds ==null){
   operationIds="";
  }if(beginTime==null){
   beginTime="";
  }if(endTime==null){
   endTime ="";
  }if(id ==null){
   id="";
  }
  List<AuditLogInfoWrapper> users = userService.saveAuditLogDataExcel(operationIds,beginTime,endTime,id);
  
   //创建excel
   HSSFWorkbook wb = new HSSFWorkbook();
      //创建sheet inner名称
      HSSFSheet sheet = wb.createSheet("2012-12-30"+"vci audit");
      // Create a new font and alter it.
      Font font = wb.createFont();
      font.setFontHeightInPoints((short)16);
      font.setFontName("Courier New");
      font.setItalic(false);
      font.setStrikeout(false);
      font.setColor(Font.COLOR_NORMAL);
      // Fonts are set into a style so create a new one to use.
      CellStyle style = wb.createCellStyle();
      style.setAlignment(CellStyle.ALIGN_LEFT);
      style.setFont(font);
    //first row (0-based)、last row  (0-based)、first column (0-based)、last column  (0-based)
      sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
      HSSFRow row0 = sheet.createRow((short)0);
      HSSFCell cell0=row0.createCell(0);
      cell0.setCellValue("VCI日志");
      cell0.setCellStyle(style);
     // Create a row and put some cells in it. Rows are 0 based.
      HSSFRow row = sheet.createRow((short)1);
      // Create a cell and put a value in it.
      row.createCell(0).setCellValue("操作");
      row.createCell(1).setCellValue("模块");
      row.createCell(2).setCellValue("客户端");
      row.createCell(3).setCellValue("操作人");
      row.createCell(4).setCellValue("时间");
      row.createCell(5).setCellValue("IP地址");
      row.createCell(6).setCellValue("结果");
      HSSFCell cell8 = row.createCell(7);
      cell8.setCellValue("描述");
     
      //list 控制数据读出
      int y=2;
      for (AuditLogInfoWrapper user:users) {
          HSSFRow row1 = sheet.createRow((short)y);
          sheet.setDefaultColumnWidth(18);
          row1.createCell(0).setCellValue(user.getOperationName());
          row1.createCell(1).setCellValue(user.getModuleName());
          row1.createCell(2).setCellValue(user.getClientType());
          row1.createCell(3).setCellValue(user.getUserName());
          row1.createCell(4).setCellValue(user.getTime());
          row1.createCell(5).setCellValue(user.getIp());
          row1.createCell(6).setCellValue(user.getResult());
          row1.createCell(7).setCellValue(user.getProperties());
       y++;
      }
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      try {
       wb.write(baos);
   }catch (IOException e) {
    e.printStackTrace();
   }
      byte[] ba=baos.toByteArray();
      ByteArrayInputStream bais=new ByteArrayInputStream(ba);
      excelStream=bais; 
  return SUCCESS;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值