/** * * 方法描述:XX审计结果输出到Excel去中 * @param auditVOList * @param type */ private String numDataWriteExcel(List auditVOList) { Date todate=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyMMddHHmmss"); String fileName="omcAudit"+sdf.format(todate)+".xls"; File saveFile=new File(this.getUpLoadPath()+fileName); WritableWorkbook wbook=null; try { wbook=Workbook.createWorkbook(saveFile); WritableSheet sheet1=this.createNewPrefixSheet(wbook, 0); /*************输出omcXX审计结果**************/ WritableCellFormat format2=new WritableCellFormat(); format2.setBorder(Border.ALL, BorderLineStyle.THIN); WritableFont font2=new WritableFont(WritableFont.TIMES,8,WritableFont.NO_BOLD); //字体、大小、粗细 font2.setColour(Colour.RED); //差异描述的颜色为红色 WritableCellFormat format3=new WritableCellFormat(font2); format3.setBorder(Border.ALL, BorderLineStyle.THIN); int currCount=0; /* 添加数据 */ for(int i=0;i<auditVOList.size();i++) { currCount++; //设置每个sheet最多装载30000条记录,如果记录数超过30000条,就创建一个新的sheet if(currCount>30000) { //EXCEL表格中sheet的个数 int sheetCount=wbook.getSheets().length; sheet1=this.createNewPrefixSheet(wbook, sheetCount); currCount=0; } MPVO numDataVO=(MPVO)auditVOList.get(i); Label blabel1=new Label(0,currCount+1,numDataVO.getXXX(),format2); sheet1.addCell(blabel1); Label blabel2=new Label(1,currCount+1,numDataVO.getXXX(),format2); sheet1.addCell(blabel2); Label blabel3=new Label(2,currCount+1,numDataVO.getXXX(),format2); sheet1.addCell(blabel3); Label blabel4=new Label(3,currCount+1,numDataVO.getXXX(),format2); sheet1.addCell(blabel4); Label blabel5=new Label(4,currCount+1,numDataVO.getXXX(),format2); sheet1.addCell(blabel5); Label blabel6=new Label(5,currCount+1,numDataVO.getXXX(),format2); sheet1.addCell(blabel6); Label blabel7=new Label(6,currCount+1,numDataVO.getXXX().toString(),format3); sheet1.addCell(blabel7); } wbook.write(); //System.out.println("******************"+wbook.getSheets().length); sheet长度 wbook.close(); return fileName; } catch (IOException e) { } catch (WriteException e) { } return null; } /** * 记录数超过30000条,就创建一个新的WAP sheet * @param wbook * @param sheetCount * @return * @throws WriteException */ private WritableSheet createNewWapSheet(WritableWorkbook wbook, int sheetCount) throws WriteException { WritableSheet sheet = wbook.createSheet("sheet"+sheetCount, sheetCount);//Excel的第一页 WritableFont font1=new WritableFont(WritableFont.TIMES,8,WritableFont.BOLD); //字体、大小、粗细 WritableCellFormat format1=new WritableCellFormat(font1); format1.setAlignment(Alignment.CENTRE); //对齐方式 format1.setBackground(Colour.GRAY_25); //背景颜色 format1.setBorder(Border.ALL, BorderLineStyle.THIN);//边框 /*****************Excel的表头********************/ Label label1=new Label(0,0,"AAAA",format1); sheet.addCell(label1); Label label2=new Label(1,0,"审计未通过的原因",format1);sheet.addCell(label2); return sheet; }