JSP download Excel problem __js

Source: Internet
Author: User
Tags first row

Download excel in JSP

The open () function of JavaScript is used here, and the background uses JXL to dynamically generate an Excel file stream.

Front Desk: Window.opne ("downexcelaction");

Background:

public void Downexcelaction () throws Rowsexceededexception, writeexception{System.out.println ("Export Excel table");
        String fileName = new SimpleDateFormat ("YYYYMMDDHHMMSS"). Format (new Date ()) + ". xls";
        String result = "Success";
        Query out data//populate the OutputStream OS in Excel;
        Writableworkbook Wbook;
            try {os = Response.getoutputstream ();
                    Response.reset ()//Empty output stream Response.setheader ("Content-disposition", "Attachment;filename=" + New String (Filename.getbytes ("GB2312"), "iso8859_1");/Set Output file header, <span style= "Font-size:18px;color: #FF6666;" > Here you can resolve the filename Chinese garbled problem </span> response.setcontenttype ("application/vnd.ms-excel");//define Output type WBO
            
            OK = workbook.createworkbook (OS)//build Excel file Writablesheet Wsheet = Wbook.createsheet ("Membership card Information", 0);//Create Sheet Define cell styles Writablefont WF = new Writablefont (writablefont.arial, writAblefont.bold, False, Underlinestyle.no_underline, Jxl.format.Colour.BLUE);
            
            Writablecellformat WCF = new Writablecellformat (WF);
            
            Set alignment wcf.setalignment (Jxl.format.Alignment.CENTRE);
            Freeze the first row of Wsheet.getsettings (). Setverticalfreeze (1);
            Wsheet.addcell (New Label (0, 0, "Inner Code", WCF));
            Wsheet.addcell (New Label (1, 0, "membership card", WCF));
            Wsheet.addcell (New Label (2, 0, "Agent", WCF));
            Wsheet.addcell (New Label (3, 0, "membership card Information", WCF));
            Wsheet.addcell (New Label (4, 0, "Membership card status", WCF));
            Wsheet.addcell (New Label (5, 0, "consumer info", WCF));
            Wsheet.addcell (New Label (6, 0, "Current balance", WCF));
            
            Wsheet.addcell (New Label (7, 0, "time", WCF));
            Return to Excel Wbook.write ();
            Wbook.close ();
        Os.close (); The catch (Exception e) {result = "Download has an exception, please contact the administrator."
            "; E.Printstacktrace (); }
        
    }


Related Article

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.