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