您的位置:首页 > 编程语言 > Java开发

创建导出excel工作流

2013-10-23 11:14 295 查看
try{
//创建Excel
WritableWorkbookexportBook=Workbook.createWorkbook(os);
StringsheetName=excelExporter.getSheetName();
if(StringUtils.isNullString(sheetName)){
sheetName=fileName;
}
WritableSheetsheet=exportBook.createSheet(sheetName,0);
MapoutputColumnViews=newHashMap();
//数据头部区域
intcurRow=excelExporter.getDataRowXIndex();
Listheaders=excelExporter.getDataHeader();
if(null!=headers&&headers.size()>0){
curRow=insertRows(headers,curRow,excelExporter,sheet,outputColumnViews);
}

//循环文件填充数据
for(inti=0;i<fileList.size();i++){
Objectentity=fileList.get(i);
if(null==entity)
continue;
ListrowData=excelExporter.toDataBodyRow(entity,i);
curRow=insertRows(rowData,curRow,excelExporter,sheet,outputColumnViews);
}
//数据尾部区域
Listfooters=excelExporter.getDataFooter();
if(null!=footers&&footers.size()>0){
curRow=insertRows(footers,curRow,excelExporter,sheet,outputColumnViews);
}
if(!outputColumnViews.isEmpty()){
for(IteratorcolumnEntryIterator=outputColumnViews.entrySet().iterator();columnEntryIterator.hasNext();){
Map.EntrycolumnViewEntry=(Map.Entry)columnEntryIterator.next();
intcolumnIndex=newInteger((String)columnViewEntry.getKey()).intValue();
intwidth=((Integer)columnViewEntry.getValue()).intValue();
sheet.setColumnView(columnIndex,width);
}
}
exportBook.write();
exportBook.close();
}catch(Exceptionex){
thrownewBusinessException(ex);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java excel 工作流