简单的导出excel基于阿里

所需maven依赖

  com.alibaba
  easyexcel
  1.1.2-beta4

 

程序代码
public void exportBatchExcel(HttpServletResponse response, List list, String fileName) throws IOException {//list集合为导出的数据
  ServletOutputStream out = null;
  out = response.getOutputStream();
  ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX, true);
  try {
    Sheet sheet = new Sheet(1, 0, QyBuildingQual.class);//QyBuildingQual自定义类
    writer.write(list, sheet);
    response.setCharacterEncoding("utf-8");
    response.setContentType("application/vnd.ms-excel");
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "utf-8"));
    out.flush();
  }catch (Exception e){
    e.printStackTrace();
  }finally {
    writer.finish();
    out.close();
  }
}

 

QyBuildingQual类

public class QyBuildingQual extends BaseRowModel {//BaseRowModel 必须继承此类
    /**
     *办件流水号
     */
    @ExcelProperty(value = "办件流水号",index =0)
    private String orderNum;

    /**
     *企业名称
     */
    @ExcelProperty(value = "企业名称",index = 2)
    private String compName;

}

你可能感兴趣的:(简单的导出excel基于阿里)