【VIP专享】java 导出excel 增量写入同一sheet

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

sheetAct=createExcelHead(sheetAct,writer,excelHead,title+num);

}

list=agentService.queryExportData(map);

if(j<5){

findExcelData(j*limit,list,sheetAct);

}else{

int num=j/5;

findExcelData((j-num*5)*limit,list,sheetAct);

}

}

writer.write();

}catch(Exception e){

LOGGER.error("Exception:", e.fillInStackTrace());

}

finally {

if (null != writer) {

writer.close();

}

}

return out.toByteArray();

}

findExcelData 方法:

private void findExcelData(int start,List list,ExcelWriter.Sheet sheetAct){

StudioSeriesPrice detail=null;

/*拼装excel内容*/

for(int i=0;i

detail=list.get(i);

sheetAct.getOrCreateCell((start+i + 1), 0).setCellStyle(sheetAct.addStyle());

sheetAct.getOrCreateCell((start+i + 1), 0).setCellValue(detail.getCompany());

sheetAct.getOrCreateCell((start+i + 1), 1).setCellStyle(sheetAct.addStyle());

sheetAct.getOrCreateCell((start+i + 1), 1).setCellValue(detail.getCreatetime());

sheetAct.getOrCreateCell((start+i + 1), 2).setCellStyle(sheetAct.addStyle());

sheetAct.getOrCreateCell((start+i + 1), 2).setCellValue(detail.getPrice());

sheetAct.getOrCreateCell((start+i + 1), 3).setCellStyle(sheetAct.addStyle());

sheetAct.getOrCreateCell((start+i + 1),

3).setCellValue(detail.getNum());

sheetAct.getOrCreateCell((start+i + 1), 4).setCellStyle(sheetAct.addStyle());

sheetAct.getOrCreateCell((start+i + 1), 4).setCellValue(detail.getTypename());

sheetAct.getOrCreateCell((start+i + 1), 5).setCellStyle(sheetAct.addStyle());

sheetAct.getOrCreateCell((start+i + 1), 5).setCellValue(detail.getAgentName());

sheetAct.getOrCreateCell((start+i + 1), 6).setCellStyle(sheetAct.addStyle());

sheetAct.getOrCreateCell((start+i + 1), 6).setCellValue(detail.getPricename());

}

}

/**

*

* @param sheetAct

* @param writer

* @param excelHead

* @param title

* @return

*/

private ExcelWriter.Sheet createExcelHead( ExcelWriter.Sheet sheetAct,ExcelWriter writer,String [] excelHead,String title){ sheetAct = writer.getOrCreateSheet(title);

/*拼装excel头部*/

for(int i=0;i

sheetAct.getOrCreateCell(0,

i).setCellStyle(sheetAct.addStyle());

sheetAct.setColumnWidth(i, 6000);

sheetAct.getOrCreateCell(0,

i).setCellValue(excelHead[i]);

}

return sheetAct;

}

帮助类:

package com.kerui.utils;

import java.io.IOException;

相关文档
最新文档