java导出excel增量写入同一sheet.doc
文本预览下载声明
代码:
response.setCharacterEncoding(utf8);
int totalcount=agentService.queryCount(map);//查询记录总数
try {
OutputStream outputStream = response.getOutputStream();
String title=影楼充值数据.xls;//excel文件名
byte[] content=findExcelData(totalcount,map,影楼充值数据);//转字节流 totalcount 总数; map 参数 ; 最后一个是sheet名称
response.setContentType(application/x-msdownload);
response.setContentLength(content.length);
response.setHeader(Content-Disposition, attachment;filename=+ new String(title.getBytes(utf-8), ISO-8859-1));
outputStream.write(content);
outputStream.flush();
outputStream.close();
}catch (IOException e) {
LOGGER.error(IOException:, e.fillInStackTrace());
}
findExcelData 方法
public byte[] findExcelData(int count,Map map,String title) {
int start=0;
int limit=2000;//一个sheet存60000条数据,超过6W条新建新sheet
ListStudioSeriesPrice list = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelWriter writer = null;
try {
writer = new ExcelWriter(out);
ExcelWriter.Sheet sheetAct = null;
String [] excelHead= {影楼名称,时间,价格,套数,类型,代理商,套系名称};
int sizes=(count/limit)+(count%limit0?1:0);
for(int j=0;jsizes;j++){
//大批量数据采用分页写入数据
map.put(start, j*limit);
map.put(limit, limit);
if(j%30==0){
int num=j/30+1;
sheetAct=createExcelHead(sheetAct,writer,excelHead,title+num);
}
list=agentService.queryExportData(map);
if(j5){
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,ListStudioSeriesP
显示全部