您的位置:首页 > Web前端 > CSS

excel导出效率慢,单元格样式复制方法分析

2016-11-23 16:01 183 查看
实现方法:
@SuppressWarnings("unchecked")
public Row copyStyle(Sheet sheet, int srcRowNum, int destRowNum) {
Row srcRow = sheet.getRow(srcRowNum);
Row destRow = sheet.createRow(destRowNum);
try{
if(srcRow.getRowStyle()!=null){//row格式的复制
destRow.setRowStyle(srcRow.getRowStyle());
}
int i=0;
Iterator<Cell> srcCells = srcRow.cellIterator();
while(srcCells.hasNext()) {
Cell srcCell = srcCells.next();
Cell destCell = destRow.createCell(i++);
//cell格式的复制
if(srcCell.getCellStyle()!=null)destCell.setCellStyle(srcCell.getCellStyle());

}
}catch(Exception e){
LOG.error("copyStyle::"+e.getMessage());
LOG.error(e);
}
return destRow;
}

调用方法:

Row row =null;
if(i==0){
row = sheet.createRow(i+6);
for (int j = 0; j < TITLES.length; j++) {
// 数据项单元格格式
Cell cell = row.createCell(j);
cell.setCellStyle(createCellStyleWithBorder(wookBook,CELL_STYPE_STRING, b));
}
}else{
row=copyStyle(sheet,i+5,i+6);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java
相关文章推荐