List<tzin> list = tzinservice.getlist (Tzin,user); String fileName = "Warehousing ledger statistics. xls"; response.setcontenttype ("application/vnd.ms-excel;charset= UTF-8 "); try { if (Request.getheader ("User-agent"). toUpperCase (). IndexOf ("MSIE") > 0) { // ie browser filename = urlencoder.encode (filename, "UTF-8"); } else { filename = new string (FileName.getBytes (" UTF-8 "), " iso8859-1 "); } response.setheader ("Content-disposition", "attachment; filename=" + filename); } catch ( UNSUPPORTEDENCODINGEXCEPTION&NBSP;E2) { e2.printstacktrace (); } WritableWorkbook web = null; ServletOutputStream sos = null; try { sos = response.getoutputstream (); web = workbook.createworkbook (SOS); writablesheet ws = web.createsheet ("Inbound Ledger Statistics", 0); ws.setcolumnview (0, 20); Ws.setcolumnview (1, 20); Ws.setcolumnview (2, 20); Ws.setcolumnview (3, 20); Ws.setcolumnview (4, 20); Ws.setcolumnview (5, 20); Ws.setcolumnview (6, 20); Ws.setcolumnview (7, 20); ws.setcolumnview (8, 20); ws.setcolumnview (9, 20); ws.setcolumnview (10, 20); writablecellformat cellformat = new writablecellformat (); // Set Cell Center cellformat.setalignment (Alignment.CENTRE); writablefont font = new writablefont (writablefont.courier, 16,writablefont.bold, true); WritableCellFormat format = new Writablecellformat (font); Format.setalignment (alignment.centre); label label0 = new label (0, 0, "unit name"); label Label1 = new label (1, 0, "Storage Time "); label label2 = new label (2, 0, "waste name"); label label3 = new label (3, 0, "waste category"); label Label4 = new label (4, 0, "Waste Code"); label label5 = new label (5, 0, "Waste form"); label label6 = new label (6, 0, "waste sources"); label label7 = new label (7, 0, "packaging form"); label label8 = new label (8, 0, "Quantity (ton)"); label label9 = new label (9, 0, "receiving warehouse "); label label10 = new label (10, 0 , "operator"); label0.setcellformat (CellFormat); label1.setcellformat (CellFormat); label2.setcellformat (CellFormat); label3.setcellformat (CellFormat); label4.setcellformat (CellFormat); label5.setcellformat (CellFormat); label6.setcellformat (CellFormat); label7.setcellformat (CellFormat); label8.setcellformat (CellFormat); label9.setcellformat (CellFormat); label10.setcellformat (CellFormat); ws.addcell (label0); &Nbsp; ws.addcell (Label1); Ws.addcell (Label2); ws.addcell (LABEL3); ws.addcell (LABEL4); ws.addcell (LABEL5); ws.addcell (LABEL6); ws.addcell (LABEL7); Ws.addcell (Label8); ws.addcell (LABEL9); ws.addcell (LABEL10); if (List != null && list.size () > 0) { for (int i = 0; i < list.size (); i++) { tzin tzin = list.get (i) ; label cname = new label (0, i+1, tzin.getcname ()); label intime = new label (1, i+1, tzin.getintime (). toString (). substring (0, &NBSP;10)); &nbsP; label wastename = new label (2, i+1, tzin.getwastename ()); Label Wastetype = new label (3, i+1, tzin.getwastetype ()); label wastecode = new label (4, i+1, tzin.getwastecode ()); label wasteform = new label (5, i+1, tztoolutil.formshow (Tzin.getwasteform ())); Label Wastesource = new labEl (6, i+1, tztoolutil.wastesourceshow (Tzin.getwastesource ())); label packageway = new label (7, i+1, tztoolutil.packagewayshow (Tzin.getpackageway ())); Label wasteamount = new label (8, i+1, string.valueof (TzIn.getWasteAmount ())); label acceptplace = new label (9, i+1, tzin.getacceptplace ()); label handleman = new label (10, i+1, tzin.gethandleman ()); cname.setcellformat ( CellFormat); intime.setcellformat (CellFormat); wastename.setcellformat (CellFormat); wastetype.setcellformat (CellFormat); wastecode.setcellformat (CellFormat); Wasteform.setcellformat (CellformaT); wastesource.setcellformat (CellFormat); packageway.setcellformat (CellFormat); wasteamount.setcellformat (CellFormat); acceptplace.setcellformat (CellFormat); Handleman.setcellformat (CellFormat); ws.addcell (CNAME); ws.addcell (inTime); ws.addcell (WasteName); ws.addcell (Wastetype); ws.addcell (Wastecode); ws.addcell (WasteForm); ws.addcell (Wastesource); ws.addcell (Packageway); ws.addcell (Wasteamount); ws.addcell (AcceptPlace); ws.addcell (Handleman); } } web.write (); sos.flush (); } catch ( Exception e) { E.printstacktrace (); } finally { try { web.close (); sos.close (); } catch (EXCEPTION&NBSP;E1) { e1.printstacktrace (); } }
This article from "Monkey also crazy" blog, declined reprint!
Java Writableworkbook Export Excel