try {//Structure 40W data list<branch> list = this.getbranch (); hssfworkbook workbook = service.createhssfworkbook (list); String fileName = "Chinese name hahaha"; outputstream out = new bufferedoutputstream (Response.getoutputstream ()); //compression download measurement 80m compress 16m Download faster if (workbook != null) { filename = filename+ dateutil.getexceldate (New date ()) + ". xls"; response.setcontenttype ( "application/octet-stream "); response.setheader ("Content-Disposition", " Attachment;filename=\ "" + java.net.urlencoder.encode (filename, "UTF-8") + ". zip" + "\" "); &nBsp Archiveoutputstream archouts = new archivestreamfactory (). CreateArchiveOutputStream ( Archivestreamfactory.zip,new bufferedoutputstream (out)); ziparchiveoutputstream zipout= (Ziparchiveoutputstream) archouts; ziparchiveentry zipentry=new ziparchiveentry (FileName); zipout.putarchiveentry (ZipEntry); workbook.write (zipout); Zipout.closearchiveentry (); zipout.flush (); zipout.finish (); out.close (); }} catch (exception e) {logger.error ("controller>>>> >>>>>>>>> reportsDownload Failed ", e);} Generate workbook @Overridepublic hssfworkbook createhssfworkbook (list<branch> list) { hssfworkbook workbook = new hssfworkbook (); long totle = list.size ();//Gets total, in Excel paging float res= Float.parsefloat (string.valueof (Totle)); int mus=40000; // XLS file a sheet up to 65,536 data float avg=res/mus; //min Sheet page for (int k = 0; k < avg; k++) { hssfsheet sheet = workbook.createsheet ("page" +k+ "); sheet.setdefaultcolumnwidth (; ) Sheet.setdefaultrowheightinpoints (; hssfcellstyle style = ) Workbook.createcellstyle (); // Creating Font Objects Font ztFont = Workbook.createfont (); hssfrow row = sheet.createrow (0); String[] headers = { "organization number", "Institution name", "organization level", "Parent institution name", "agency leader", "agency head Contact", "agency status", "Landline Phone"}; for (short i = 0; i < headers.length; i++) { hssfcell cell = row.createcell (i); Hssfrichtextstring text = new hssfrichtextstring (Headers[i]); cell.setcellvalue (text);} Processing Loops Sheet Page List<Branch> tempList = null; int last = (int) (avg); if (k== (last-1)) { int index = (int) (K*mus); //templist = List.sublist (Index, list.size ()); //resolve sublist causes memory not to be recycled, memory overflow Templist = this. Mysublist (List,index,list.size ()); }else{ int index = (int) (k*mus); //templist = list.sublist (Index,index+mus); templist = this. Mysublist (List,index,index+mus); } for (int i=1,j=0;j <templist.size (); i++,j++) { row = Sheet.createrow (i); branch br = templist.get (j); hssfcell cell = row.createcell (0); this.setcellstyle (Style,ztfont,cell); cell.setcellvalue (Br.getbranchid () == null ? "" : br.getbranchid ()); cell = row.createcell (1); this.setcellstyle (Style,ztFont,cell); cell.setcellvalue (Br.getbranchname () == null ? "" : br.getbranchname ()); cell = Row.createcell (2); this.setcellstyle (Style,ztFont,cell); string branchlevel = br.getbranchlevel (); if (branchlevel != null) { if (Branchlevel.equals ("1")) { cell.setcellvalue ("A"); }else if (Branchlevel.equals ("2")) { cell.setcellvalue ("B"); } }else{ cell.setcellvalue (""); }cell = row.createcell (3); This.setcellstyle (Style,ztfont,cell); Cell.setCellValue ( Br.getparentbranchname () == null ? " : br.getparentbranchname ()); cell = row.createcell (4); This.setcellstyle (Style,ztfont,cell); Cell.setcellvalue (Br.getheadername () == null ? "" : br.getheadername ()); Cell = row.createcell (5); This.setcellstyle (Style,ztfont,cell); Cell.setcellvalue (Br.getheaderphone () == null ? "" : Br.getheaderphone ()); Cell = row.createcell (6); This.setcellstyle (Style,ztfont,cell); String branchstate = br.getbrancHstate (); if (branchstate != null) {if (Branchstate.equals ("1")) { Cell.setcellvalue ("Enabled");} Else if (Branchstate.equals ("2")) { cell.setcellvalue ("not Enabled");}} Else{ cell.setcellvalue ("");} Cell = row.createcell (7); This.setcellstyle (Style,ztfont,cell); Cell.setcellvalue (Br.getBranchPhone () == null ? "" : br.getbranchphone ());}} Return workbook;}
Poi Apache compress for Excel compression download