欢迎来到天天文库
浏览记录
ID:34723826
大小:101.68 KB
页数:6页
时间:2019-03-10
《java导出excel增量写入同一sheet》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、代码:response.setCharacterEncoding("utf8");inttotalcount=agentService.queryCount(map);//查询记录总数try{OutputStreamoutputStream=response.getOutputStream();Stringtitle="影楼充值数据.xls";//excel文件名byte[]content=findExcelData(totalcount,map,"影楼充值数据");//转字节流totalcount总数;map参数;最后一个是sheet名称response.setContent
2、Type("application/x-msdownload");response.setContentLength(content.length);response.setHeader("Content-Disposition","attachment;filename="+newString(title.getBytes("utf-8"),"ISO-8859-1"));outputStream.write(content);outputStream.flush();outputStream.close();}catch(IOExceptione){LOGGER.error(
3、"IOException:",e.fillInStackTrace());}findExcelData方法publicbyte[]findExcelData(intcount,Mapmap,Stringtitle){intstart=0;intlimit=2000;//一个sheet存60000条数据,超过6W条新建新sheetListlist=null;ByteArrayOutputStreamout=newByteArrayOutputStream();ExcelWriterwriter=null;try{writer=newExcel
4、Writer(out);ExcelWriter.SheetsheetAct=null;String[]excelHead={"影楼名称","时间","价格","套数","类型","代理商","套系名称"};intsizes=(count/limit)+(count%limit>0?1:0);for(intj=0;j5、,writer,excelHead,title+num);}list=agentService.queryExportData(map);if(j<5){findExcelData(j*limit,list,sheetAct);}else{intnum=j/5;findExcelData((j-num*5)*limit,list,sheetAct);}}writer.write();}catch(Exceptione){LOGGER.error("Exception:",e.fillInStackTrace());}finally{if(null!=writer){writer6、.close();}}returnout.toByteArray();}findExcelData方法:privatevoidfindExcelData(intstart,Listlist,ExcelWriter.SheetsheetAct){StudioSeriesPricedetail=null;/*拼装excel内容*/for(inti=0;i7、t.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.
5、,writer,excelHead,title+num);}list=agentService.queryExportData(map);if(j<5){findExcelData(j*limit,list,sheetAct);}else{intnum=j/5;findExcelData((j-num*5)*limit,list,sheetAct);}}writer.write();}catch(Exceptione){LOGGER.error("Exception:",e.fillInStackTrace());}finally{if(null!=writer){writer
6、.close();}}returnout.toByteArray();}findExcelData方法:privatevoidfindExcelData(intstart,Listlist,ExcelWriter.SheetsheetAct){StudioSeriesPricedetail=null;/*拼装excel内容*/for(inti=0;i7、t.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.
7、t.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.
此文档下载收益归作者所有