欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java开发easypoi导出excel表格数据

程序员文章站 2023-11-29 17:41:04
@ApiOperation(value = "列表数据导出")@PostMapping(value = "/preFollowListExport", produces = "application/json;charset=UTF-8") public Response export(HttpServletResponse servletResponse) throws IOException { String nam....
@ApiOperation(value = "列表数据导出")
@PostMapping(value = "/preFollowListExport", produces = "application/json;charset=UTF-8")
    public void export(HttpServletResponse servletResponse) throws IOException {
      
                String name = "数据表";
                servletResponse.setHeader("content-Type", "application/vnd.ms-excel");
                servletResponse.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name + ".xls", "utf-8"));
                servletResponse.setHeader("Access-Control-Expose-Headers", "ContentDisposition");
                
                //获取数据源
                List<DataBean> list = null;

                ExportParams params = new ExportParams(name, "sheet1");
                Workbook workbook = ExcelExportUtil.exportBigExcel(params, DataBean.class, list);
                ExcelExportUtil.closeExportBigExcel();
                try {
                    workbook.write(servletResponse.getOutputStream());
                }catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    workbook.close();
                }
           
  
    }

 

 

数据实体对象:

@Data
@ExcelTarget(value = "dataBean")
public class DataBean implements Serializable {

    @Excel(name = "序号")
    private Integer sortNum;

    @Excel(name = "姓名")
    private String name;
}

 

本文地址:https://blog.csdn.net/qq_34707456/article/details/107069917