审计出结果EXCEL导出

本文介绍了一种将大量审计结果数据导出至Excel文件的方法。该方法能够处理超过30,000条记录的数据,并根据记录数量动态创建新的工作表。文章详细描述了如何使用JXL库创建和格式化Excel文件,包括数据写入、样式设置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


/**
*
* 方法描述: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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值