Java Excel Export

Source: Internet
Author: User

Read the next colleague wrote the export Excel is easy to write down to spare

1, add the necessary jar package Poi-3.10-final-20140208.jar

2. New file name "Xxxx.xlsx"

3, Workbook wb = null;

4, Workbook wb = new Xssfworkbook ();

5, Sheet Sheet = Wb.createsheet (fileName);

6. string[] title = {"Contract number"}

7, Row titlerow = sheet.createrow (0);

8. Initialize the table header

private void Initialiserow (Row row,string[] title) {
for (int i = 0; i < title.length; i++) {
Cell cell = Row.createcell (i);
Cell.setcellvalue (Title[i]);
}
}

9. Fill data

for (int i = 0; i < list.size (); i++) {
Row row = Sheet.createrow (i+1);
Row.createcell ((short) 0). Setcellvalue (List.get (i). GetCode ());

}

10. Responding to requests

OutputStream OS = null;
try {
OS = new Bufferedoutputstream (Response.getoutputstream ());//Get output stream
Response.reset ();//emptying the output stream
Response.AddHeader ("Content-disposition", "Attachment;filename="
+ New String (Filename.getbytes ("GBK"), "iso8859-1"));
Response.setcontenttype ("Application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Response.setcharacterencoding ("Utf-8");
Wb.write (OS);
Os.flush ();
Os.close ();
} catch (IOException e) {
Logger.error ("Error in exporting an Excel purchase condition:", e);
}


Java Excel Export

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.