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;
}
struts2 poi导出excel函数
最新推荐文章于 2012-02-14 15:12:16 发布