Export of ali Excel

1. Introduced maven dependence 

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>easyexcel</artifactId>
    <version>1.1.2-beta5</version>
</dependency>

2. On the entity class annotate

@ExcelProperty (value = "column name", index = index of the column) 

entity classes to inherit BaseRowModel class

3.

List <entity class> list = acquired set of data to export. 
Sheet Sheet = new new Sheet (1,0, entity class. Class ); // definition of a sheet
{the try 
response.setHeader ( "Access-Control-Expose-Headers", "the Content-Disposition");
response.setHeader ( "the Content-Disposition", "Attachment; filename =" + the URLEncoder.encode (sheetName, "UTF-. 8 ") +" .xlsx ");
the OutputStream response.getOutputStream OUT = ();
ExcelWriter Writer = EasyExcelFactory.getWriter (OUT); //
sheet.setSheetName (sheetName); // set the name of the sheet
writer.write (list, sheet ); // write data to the sheet set list above
writer.finish ();
} the catch (IOException E) {
logger.info ( "export table problems" + e.getMessage ());
}

 

Guess you like

Origin www.cnblogs.com/huoyufei/p/11429755.html