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