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);
}
@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方法,并且已解决导出会有样式文件夹的问题
- .net 导出Excel,设置Excel页眉及单元格换行方法
- C#导出Excel,某单元格内容长度超过255 的解决方法
- MySQL实现导出excel的方法分析
- win7 64位系统web项目导出excel问题分析及解决方法汇总
- java中excel导出包括合并单元格和单元格样式
- poi导出excel单元格样式设置
- C# 导出excel单个单元格内容超出当前范围解决方法
- java jxl 导出excel 附带导出图片和单元格样式
- 导出excel身份证过长导致显示不正常自定义单元格格式解决方法
- 用NPOI创建Excel、合并单元格、设置单元格样式、边框的方法
- 导出excel时需要在单元格进行强制换行2003与2007方法一样
- JavaEE_POI导出Excel, 设置导出Excel 单元格样式
- 用NPOI创建Excel、合并单元格、设置单元格样式、边框的方法
- ASP.NET Export to Excel(导出数据到Excel) & C#导出Excel,某单元格内容长度超过255的处理方法
- java中导出excel设置单元格的样式为数字格式
- html table表格导出excel的方法 html5 table导出Excel HTML用JS导出Excel的五种方法 html中table导出Excel 前端开发 将table内容导出到excel HTML table导出到Excel中的解决办法 js实现table导出Excel,保留table样式
- java实现web的table导出到excel的3种方法分析
- aix英文版导出excel单元格内容显示不全简单解决方法
- POI中导出Excel单元格样式(居中,字体,边框等)