JAVA Export Excel2003 format file implementation code

Source: Internet
Author: User

1      Publicstring Exportexcel (string name, String name2, String name3,2 string name4, String name5, HttpServletRequest request,3 httpservletresponse Response) {4         5String Path = Request.getrealpath ("/");6List List = This. Findvsendlist (name,name2,name3,name4,name5);7Writableworkbook book =NULL;8         intpagernum,mus=65535, Count,num;9Writablesheet sheet =NULL;Ten      One         Try { A  -             //Insert Table page in front of position 0 -OutputStream OS = Response.getoutputstream ();//Get output stream theResponse.reset ();//emptying the output stream -Response.setheader ("Content-disposition", "attachment; Filename= "+NewString ("file name". GetBytes ("GB2312"), "8859_1") + ". xls");//Set Output file header -Response.setcontenttype ("Application/msexcel");//defining the output type -  +Book =workbook.createworkbook (OS); -Pagernum=list.size ()/mus; +              for(inti=0;i<pagernum+1;i++){ ASheet = book.createsheet ("sheet" + (i+1), i); at  -                 //Delete Page -Sheet.addcell (NewLabel (0, 0, "column One"));//position starting from 0 -  -Sheet.addcell (NewLabel (1, 0, "column two")); -                  inSheet.addcell (NewLabel (2, 0, "column three")); -                  toSheet.addcell (NewLabel (3, 0, "column four")); +                  -Sheet.addcell (NewLabel (4, 0, "column five")); the                  *Sheet.addcell (NewLabel (5, 0, "column six")); $                 Panax NotoginsengSheet.addcell (NewLabel (6, 0, "column seven")); -                  theSheet.addcell (NewLabel (7, 0, "column eight")); +                  A                 if(i==pagernum) { theCount=list.size ()%mus; +}Else{ -Count=mus; $                 } $num=i*mus; -                  -                  for(intj = num; J < Num+count; J + +) { theVsendlist sendlist =(Vsendlist) List.get (j);  -                     if(Sendlist! =NULL) {WuyiString Type = ""; the                         if(1 = =sendlist.getxx ()) { -Type = "XX"; Wu}Else if(2 = =sendlist.getxx ()) { -Type = "XX";  About}Else if(3 = =sendlist.getxx ()) { $Type = "XX"; -}Else { -Type = "XX"; -                         } ASheet.addcell (NewLabel (0, J + 1-num, Sendlist.getxxxx ()));//position starting from 0 +Sheet.addcell (NewLabel (1, j + 1-num, Sendlist.getxx ())); theSheet.addcell (NewLabel (2, J + 1-num, sendlist.getxxxx ())); -Sheet.addcell (NewLabel (3, J + 1-num, Type)); $Sheet.addcell (NewLabel (4, J + 1-num, sendlist.getxxxxx (). substring (0, 19))); theSheet.addcell (NewLabel (5, J + 1-num, sendlist.getxxxxxx ())); theSheet.addcell (NewLabel (6, J + 1-num, Sendlist.getxxxxxx (). toString ())); theSheet.addcell (NewLabel (7, J + 1-num, sendlist.getxxxxx ())); the                     } -                 } in             } the book.write (); the}Catch(Exception e) { About e.printstacktrace (); the}finally { the             if(Book! =NULL) { the                 Try { + book.close (); -}Catch(Exception e) { the e.printstacktrace ();Bayi                 } the             } the         } -         return NULL; -}

JAVA Export Excel2003 format file implementation code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.