首页 > 代码库 > excel导出效率慢,单元格样式复制方法分析
excel导出效率慢,单元格样式复制方法分析
实现方法:
@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);
}
excel导出效率慢,单元格样式复制方法分析