导入1

  1. 导入依赖
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi</artifactId>
</dependency>

或者

<dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-base</artifactId>
    <version>4.2.0</version>
</dependency>

controller

@ApiOperation(value = "工地分包情况月报表-导入", tags = {SwaggerTagConstants.ADMIN})
    @POST
    @Path("import")
    @Consumes({"multipart/form-data"})
    @Authorization(permission = "siteSubcontract:add,siteSubcontract:update")
    public WebApiResponse importSysDepart(@Context SecurityContext context, @FormDataParam("file") InputStream inputStream
            ,@QueryParam("filetype")String filetype,@QueryParam("districtname")String districtname) {
        Map<String, String> map = siteSubcontractService.importExcel(inputStream, 1l, filetype, districtname);
        if (map!=null&&map.get("code").equals("400")){
            return new WebApiResponse(400, map.get("msg"), null);
        }
         return done();
    }
  1. 手动导入方法实现
@Override
    @Transactional
    public synchronized Map<String,String> importExcel(InputStream inputStream,Long userid,String filetype,String districtname){
        Map<String,String> msgMap = new HashMap<>();
        msgMap.put("code","0");
        try {
            Workbook wb;
            if ("xls".equals(filetype)){
                wb = new HSSFWorkbook(inputStream);
            }else if ("xlsx".equals(filetype)){
                wb = new XSSFWorkbook(inputStream);
            }else {
                wb = new XSSFWorkbook(inputStream);
            }
            //开始解析
            Sheet sheet = wb.getSheetAt(0);
            //获取标题行
            Row title = sheet.getRow(1);
            String titleStr = title.getCell(0).toString();
            int flag = 0;
            for (int i = 0;i < titleStr.length();i++){
                if(String.valueOf(titleStr.charAt(i)).equals("区")||String.valueOf(titleStr.charAt(i)).equals("市")
                        ||String.valueOf(titleStr.charAt(i)).equals("县")){
                    flag = i+1;
                }
            }
            //获取区名
            String area = titleStr.substring(0, flag);
            //判断截取的区名是否存在数据库中
            SysDepart byDepartNameSub = sysDepartRepository.findByDepartName(area);
            if(byDepartNameSub == null||byDepartNameSub.equals("")){
                msgMap.put("code","400");
                msgMap.put("msg","请输入正确的区域名称");
                return msgMap;
            }
            if (!districtname.equals(area)){
                msgMap.put("code","400");
                msgMap.put("msg","所传文件区域与所选区域不符,请重新选择上传文件");
                return msgMap;
            }
            if (area.equals("")||area==null){
                msgMap.put("code","400");
                msgMap.put("msg","表格标题格式错误,请以XXX区(市/县)开头");
                return msgMap;
            }
            int firstRowIndex = sheet.getFirstRowNum() + 5;
            int lastRowIndex = sheet.getLastRowNum();
            List<SiteSubcontractDto> dtos = new LinkedList<>();
            String pinyinszm = Arith.getPinyinszm(byDepartNameSub.getDepartName());
            Map<String, String> getqynum = this.getqynum(pinyinszm);
            int sz = 0;
            if(getqynum.size()>0&&!StringUtils.isEmpty(getqynum.get("sz"))){
                sz = Integer.valueOf(getqynum.get("sz"));
            }
            for (int rIndex = firstRowIndex; rIndex <= lastRowIndex; rIndex++) {
                sz = sz + 1;
                SiteSubcontractDto dto = new SiteSubcontractDto();
                dto.setOrgcode(byDepartNameSub.getOrgCode());
                dto.setDepartid(byDepartNameSub.getId());
                dto.setArea(byDepartNameSub.getDepartName());
                String qynum = Arith.getqynum(pinyinszm,sz);
                dto.setSitenum(qynum);
                dto.setNum(String.valueOf(sz));
                Row row = sheet.getRow(rIndex);
                String validobj = validobj(row.getCell(0));
                if("合计".equals(validobj)){
                    break;
                }else{
                    int setvalue = setvalue(dto, rIndex, sheet);
                    dtos.add(dto);
                    rIndex = setvalue;
                }

            }
                if(dtos.size()>0){
                    this.saveAll(dtos);
                }



        } catch (IOException e) {
            e.printStackTrace();
        }
        return msgMap;
    }

导出

  1. 依赖

com.alibaba easyexcel 2.1.4

2. 导出controller方法

@ApiOperation(value = "工地分包情况月报表-导出", tags = {SwaggerTagConstants.ADMIN})
    @POST
    @Path("export")
    @Authorization(permission = "siteSubcontract:list")
    public void exportSiteSubcontractList(@Context SecurityContext context, @Context HttpServletResponse response, Query query
            ,@QueryParam("districtname")String districtname) {
        if(StringUtils.isEmpty(districtname)){
            districtname = "中原区";
        }
         String title = "工地分包情况月报表信息表";
        List<SiteSubcontractDto> siteSubcontractList = siteSubcontractService.getSiteSubcontractList(query);
        LinkedList<SiteSubcontractDto> linklists = new LinkedList<>();
        for(int j=0;j<siteSubcontractList.size();j++){
            SiteSubcontractDto obj = siteSubcontractList.get(j);
            String[] unitsobjects = obj.getUnits().split(",");
            String[] namesobjects = obj.getNames().split(",");
            String[] phonenumbersobjects = obj.getPhonenumbers().split(",");
            String[] positionsobjects = obj.getPositions().split(",");
            for(int i=0;i<4;i++){
                SiteSubcontractDto obj1 = setvalue(obj, unitsobjects, namesobjects, phonenumbersobjects, positionsobjects, i);
                obj.setOrdernum(String.valueOf(j));
                linklists.add(obj1);
            }
        };
        try {
            this.exportExcel(response,linklists,districtname,siteSubcontractList);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public SiteSubcontractDto setvalue(SiteSubcontractDto obj,String[] utils,String[] names,String[] phonenum,String[] positions,int i){
        SiteSubcontractDto clone = null;
        try {
            clone = (SiteSubcontractDto)obj.clone();
            try {
                clone.setUnits(validobj(utils[i]));
            }catch (Exception e){
                clone.setUnits("");
            }
            try {
                clone.setNames(validobj(names[i]));
            }catch (Exception e){
                clone.setNames("");
            }
            try {
                clone.setPhonenumbers(validobj(phonenum[i]));
            }catch (Exception e){
                clone.setPhonenumbers("");
            }
            try {
                clone.setPositions(validobj(positions[i]));
            }catch (Exception e){
                clone.setPositions("");
            }
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

            return clone;
    }

    //根据单元格数据类型返回
    public String validobj(Object obj){
        if(!StringUtils.isEmpty(obj)){
            return String.valueOf(obj);
        }
        return "";
    }
    private WebApiResponse exportExcel(@Context HttpServletResponse response, List<SiteSubcontractDto> pilebodycheckMonthDtoList,String departName,List<SiteSubcontractDto> lists) throws IOException {
//        for (int i = 1; i <= pilebodycheckMonthDtoList.size(); i++) {
//            pilebodycheckMonthDtoList.get(i - 1).setOrdernum(i + "");
//        }
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
        String fileName = URLEncoder.encode(departName+"建筑垃圾排放工地四级责任分包台账统计表", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xls");
        //内容样式策略
        WriteCellStyle contentWriteCellStyle = ExcelContentStyle.getWriteCellStyle();
        //头策略使用默认
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 字体策略
        WriteFont contentWriteFont = new WriteFont();
        // 字体大小
        contentWriteFont.setFontHeightInPoints((short) 12);
        headWriteCellStyle.setWriteFont(contentWriteFont);
        headWriteCellStyle.setFillBackgroundColor((short) 0);
        EasyExcel.write(response.getOutputStream(), SiteSubcontractDto.class)
                .excelType(ExcelTypeEnum.XLS).head(SiteSubcontractDto.class)
                .registerWriteHandler(new SiteSheetWriteHandler())
                .registerWriteHandler(new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle))
                .sheet(departName+"建筑垃圾排放工地四级责任分包台账统计表")
                .useDefaultStyle(true).relativeHeadRowIndex(3)
                .doWrite(siteSubcontractService.addSumColomn(pilebodycheckMonthDtoList,lists));
        return new WebApiResponse(200, "生成excel文件成功", null);
    }

拦截器

package com.jpxx.admin.sitesubcontract.web.api;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.WorkbookWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import com.jpxx.admin.sitesubcontract.service.api.dto.SiteSubcontractDto;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;

public class SiteSheetWriteHandler implements WorkbookWriteHandler {
    @Override
    public void beforeWorkbookCreate() {

    }

    @Override
    public void afterWorkbookCreate(WriteWorkbookHolder writeWorkbookHolder) {

    }

    @Override
    public void afterWorkbookDispose(WriteWorkbookHolder writeWorkbookHolder) {
        Workbook workbook = writeWorkbookHolder.getWorkbook();
        Sheet sheet = workbook.getSheetAt(0);
        String sheetName = sheet.getSheetName();
        String departName = sheetName.replace("建筑垃圾排放工地四级责任分包台账统计表", "");
        Row row1 = sheet.createRow(0);
        row1.setHeight((short) 500);
        Cell cell = row1.createCell(0);
        //设置单元格内容
        cell.setCellValue("附件2");
        //设置标题
        Row row2 = sheet.createRow(1);
        row2.setHeight((short) 800);
        Cell cell1 = row2.createCell(0);
        cell1.setCellValue(departName+"(建筑垃圾排放工地四级责任分包台账统计表");
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        Font font = workbook.createFont();
        font.setBold(true);
        font.setFontHeightInPoints((short) 30);
        font.setFontHeight((short) 200);
        cellStyle.setFont(font);
        cell1.setCellStyle(cellStyle);
        sheet.addMergedRegionUnsafe(new CellRangeAddress(1, 1, 0, 20));
        //设置填表日期,填报人,联系方式
        Row row3 = sheet.createRow(2);
        row3.setHeight((short) 500);
        row3.createCell(1).setCellValue("填表日期");
        row3.createCell(12).setCellValue("填表人");
        row3.createCell(18).setCellValue("联系方式");

        int firstRowIndex = sheet.getFirstRowNum() + 5;
        int lastRowIndex = sheet.getLastRowNum();
        for (int rIndex = firstRowIndex; rIndex <= lastRowIndex; rIndex++) {
            Row row = sheet.getRow(rIndex);
            String validobj = validobj(row.getCell(0));
            if("合计".equals(validobj)){
                break;
            }else{
                for(int i=0;i<=18;i++){
                    sheet.addMergedRegionUnsafe(new CellRangeAddress(rIndex, rIndex+3, i, i));
                }


                rIndex = rIndex+3;
            }

        }
    }

    //根据单元格数据类型返回
    public String validobj(Object obj){
        if(!StringUtils.isEmpty(obj)){
            return String.valueOf(obj);
        }
        return "";
    }
}

添加合计

@Override
    public List<SiteSubcontractDto> addSumColomn(List<SiteSubcontractDto> lists,List<SiteSubcontractDto> sitelists) {
        double totalgarbage = 0;
        double rubbishcurrentmonthgovernance = 0;
        double rubbishgrandtotalgovernance = 0;
        double rubbishdirectutilization = 0;
        double rubbishrecyclingamount = 0;
        double totalspoil = 0;
        double spoilcurrentmonthgovernance = 0;
        double spoilgrandtotalgovernance = 0;
        SiteSubcontractDto multiLineHeadExcelModel = new SiteSubcontractDto();
        for (int i = 0;i < sitelists.size();i++){
            if (!StringUtils.isEmpty(sitelists.get(i).getTotalgarbage())){
                totalgarbage += Double.valueOf(sitelists.get(i).getTotalgarbage());
            }
            if (!StringUtils.isEmpty(sitelists.get(i).getRubbishcurrentmonthgovernance())){
                rubbishcurrentmonthgovernance += Double.valueOf(sitelists.get(i).getRubbishcurrentmonthgovernance());
            }
            if (!StringUtils.isEmpty(sitelists.get(i).getRubbishgrandtotalgovernance())){
                rubbishgrandtotalgovernance += Double.valueOf(sitelists.get(i).getRubbishgrandtotalgovernance());
            }
            if (!StringUtils.isEmpty(sitelists.get(i).getRubbishdirectutilization())){
                rubbishdirectutilization += Double.valueOf(sitelists.get(i).getRubbishdirectutilization());
            }
            if (!StringUtils.isEmpty(sitelists.get(i).getRubbishrecyclingamount())){
                rubbishrecyclingamount += Double.valueOf(sitelists.get(i).getRubbishrecyclingamount());
            }
            if (!StringUtils.isEmpty(sitelists.get(i).getTotalspoil())){
                totalspoil += Double.valueOf(sitelists.get(i).getTotalspoil());
            }
            if (!StringUtils.isEmpty(sitelists.get(i).getSpoilcurrentmonthgovernance())){
                spoilcurrentmonthgovernance += Double.valueOf(sitelists.get(i).getSpoilcurrentmonthgovernance());
            }
            if (!StringUtils.isEmpty(sitelists.get(i).getSpoilgrandtotalgovernance())){
                spoilgrandtotalgovernance += Double.valueOf(sitelists.get(i).getSpoilgrandtotalgovernance());
            }
            multiLineHeadExcelModel.setOrdernum("合计").setTotalgarbage(totalgarbage).setRubbishcurrentmonthgovernance(rubbishcurrentmonthgovernance)
                    .setRubbishgrandtotalgovernance(rubbishgrandtotalgovernance).setRubbishdirectutilization(rubbishdirectutilization).setRubbishrecyclingamount(rubbishrecyclingamount).setTotalspoil(totalspoil)
                    .setSpoilcurrentmonthgovernance(spoilcurrentmonthgovernance).setSpoilgrandtotalgovernance(spoilgrandtotalgovernance);
        }

        lists.add(multiLineHeadExcelModel);
        return lists;
    }

实体类

package com.jpxx.admin.sitesubcontract.service.api.dto;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@AllArgsConstructor
@Accessors(chain = true)
@NoArgsConstructor
@ApiModel(value = "SiteSubcontractDto", description = "工地分包情况月报表")
public class SiteSubcontractDto implements Cloneable {

    @ExcelIgnore
    @ApiModelProperty(value = "id")
    private String id;

    @ExcelIgnore
    @ApiModelProperty(value = "工地编号(格式:例 siteEQQ0001)")
    private String sitenum;

    @ExcelIgnore
    @ApiModelProperty(value = "工地编号(格式:例 siteEQQ0001)数字")
    private String num;

    @ExcelProperty(value = {"序号","序号"},index = 0)
    @ApiModelProperty(value = "序号")
    private String ordernum;

    @ExcelProperty(value = {"工地名称","工地名称"},index = 1)
    @ApiModelProperty(value = "工地名称")
    private String sitename;

    @ExcelProperty(value = {"工地详细位置","工地详细位置"},index = 2)
    @ApiModelProperty(value = "工地详细位置")
    private String adress;

    @ExcelIgnore
    @ApiModelProperty(value = "区")
    private String area;

    @ExcelIgnore
    @ApiModelProperty(value = "经度")
    private double longitude;

    @ExcelIgnore
    @ApiModelProperty(value = "纬度")
    private double latitude;

    @ExcelProperty(value = {"建设单位","建设单位"},index = 3)
    @ApiModelProperty(value = "建设单位")
    private String buildunit;

    @ExcelProperty(value = {"施工单位","施工单位"},index = 4)
    @ApiModelProperty(value = "施工单位")
    private String constructionunit;

    @ExcelProperty(value = {"所属乡(镇、办)","所属乡(镇、办)"},index = 5)
    @ApiModelProperty(value = "所属乡(镇、办)")
    private String officecodename;

    @ExcelProperty(value = {"该工地拆迁垃圾治理情况","预计产生量(万方)"},index = 6)
    @ApiModelProperty(value = "拆迁垃圾预计产生量(万方)")
    private double totalgarbage;

    @ColumnWidth(15)
    @ExcelProperty(value = {"该工地拆迁垃圾治理情况","当月拆迁垃圾治理量(万方)"},index = 7)
    @ApiModelProperty(value = "当月拆迁垃圾治理量(万方)")
    private double rubbishcurrentmonthgovernance;

    @ColumnWidth(15)
    @ExcelProperty(value = {"该工地拆迁垃圾治理情况","截止目前拆迁垃圾累计治理量(万方)"},index = 8)
    @ApiModelProperty(value = "截止目前拆迁垃圾累计治理量(万方)")
    private double rubbishgrandtotalgovernance;

    @ColumnWidth(30)
    @ExcelProperty(value = {"该工地拆迁垃圾治理情况","拆迁垃圾直接利用量(现场粉碎成石子或骨料)(万方)"},index = 9)
    @ApiModelProperty(value = "拆迁垃圾直接利用量")
    private double rubbishdirectutilization;

    @ColumnWidth(15)
    @ExcelProperty(value = {"该工地拆迁垃圾治理情况","拆迁垃圾再生利用量(加工厂再生产品砖、骨料、砂浆、水稳、混凝土装配式、墙板楼板、粉碎成石子)(万方)"},index = 10)
    @ApiModelProperty(value = "拆迁垃圾回收利用量")
    private double rubbishrecyclingamount;

    @ColumnWidth(15)
    @ExcelProperty(value = {"该工地拆迁垃圾治理情况","拆迁垃圾垃圾资源化利用方式及消纳利用地点"},index = 11)
    @ApiModelProperty(value = "拆迁垃圾垃圾资源化利用方式及消纳利用地点")
    private double rubbishdealadress;

    @ExcelProperty(value = {"该工地拆迁垃圾治理情况","拆迁垃圾运输公司名称"},index = 12)
    @ApiModelProperty(value = "拆迁垃圾运输公司名称")
    private String rubbishtransportcompany;

    @ExcelProperty(value = {"该工地工程弃土治理情况","工程弃土预计产生量(万方)"},index = 13)
    @ApiModelProperty(value = "工程弃土预计产生量(万方)")
    private double totalspoil;

    @ExcelProperty(value = {"该工地工程弃土治理情况","当月工程弃土治理量(万方)"},index = 14)
    @ApiModelProperty(value = "当月工程弃土治理量(万方)")
    private double spoilcurrentmonthgovernance;

    @ExcelProperty(value = {"该工地工程弃土治理情况","截止目前工程弃土累计治理量(万方)"},index = 15)
    @ApiModelProperty(value = "截止目前工程弃土累计治理量(万方)")
    private double spoilgrandtotalgovernance;

    @ExcelProperty(value = {"该工地工程弃土治理情况","工程弃土治理方式"},index = 16)
    @ApiModelProperty(value = "工程弃土治理方式")
    private String spoilgovernance;

    @ExcelProperty(value = {"该工地工程弃土治理情况","工程弃土消纳地点名称"},index = 17)
    @ApiModelProperty(value = "工程弃土消纳地点名称")
    private double spoildealadress;

    @ExcelProperty(value = {"该工地工程弃土治理情况","工程弃土运输公司名称"},index = 18)
    @ApiModelProperty(value = "工程弃土运输公司名称")
    private String spoiltransportcompany;

    @ExcelIgnore
    @ApiModelProperty(value = "工程弃土直接利用量")
    private double spoildirectutilization;

    @ExcelIgnore
    @ApiModelProperty(value = "工程弃土再生利用量")
    private double spoilrecyclingamount;

//    @ExcelIgnore
    @ExcelProperty(value = {"四级分包情况","单位"},index = 19)
    @ApiModelProperty(value = "单位")
    private String units;

//    @ExcelIgnore
    @ExcelProperty(value = {"四级分包情况","姓名"},index = 20)
    @ApiModelProperty(value = "姓名")
    private String names;

//    @ExcelIgnore
    @ExcelProperty(value = {"四级分包情况","职务"},index = 21)
    @ApiModelProperty(value = "职务")
    private String positions;

//    @ExcelIgnore
    @ExcelProperty(value = {"四级分包情况","手机号"},index = 22)
    @ApiModelProperty(value = "手机号")
    private String phonenumbers;

    @ExcelProperty(value = {"该工地拆迁垃圾、工程弃土治理全部完毕日期(工地治理完毕后,该工地台账信息不删除)","该工地拆迁垃圾、工程弃土治理全部完毕日期(工地治理完毕后,该工地台账信息不删除)"},format = "yyyy/MM/dd",index = 23)
    @ApiModelProperty(value = "该工地拆迁垃圾、工程弃土治理全部完毕日期(工地治理完毕后,该工地台账信息不删除)")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date allovertime;

    @ExcelIgnore
    @ApiModelProperty(value = "区域代码")
    private String orgcode;

    @ExcelIgnore
    @ApiModelProperty(value = "拆迁垃圾治理完毕时间")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date garbagetime;

    @ExcelIgnore
    @ApiModelProperty(value = "工程弃土治理完毕时间")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date spoiltime;

    @ExcelIgnore
    @ApiModelProperty(value = "工地状态(已完工或正在治理)")
    private String status;

    @Override
    public Object clone() throws CloneNotSupportedException {
        SiteSubcontractDto o = null;
         try {
                o = (SiteSubcontractDto) super.clone();
            } catch (CloneNotSupportedException e) {
                    System.out.println(e.toString());
                 }
         return o;
    }

    @ExcelIgnore
    @ApiModelProperty(value = "区域id")
    private String departid;

}
@postMapping("pilebodystatisticsmonthexport")
public WebApiResponse<List<PilebodycheckMonthDto>> pilebodystatisticsmonthexport (HttpServletResponse response,String month) throws IOException { 
    List<PilebodycheckMonthDto> pilebodysList = pilebodycheckService.pilebodystatisticsmonth(sysDepartDto, month);
   //设置序号
    for (int i = 1;i <= pilebodysList.size();i++){
        pilebodysList.get(i-1).setOrderNum(i+"");
    }
    response.setContentType("application/vnd.ms-excel");
    response.setCharacterEncoding("utf-8");
    // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
    String fileName = URLEncoder.encode("存量建筑垃圾堆体治理进度月报表", "UTF-8");
    response.setHeader("Content-disposition",  "attachment;filename=" + fileName + ".xls");
    //内容样式策略
    WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
    //垂直居中,水平居中
    contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
    contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
    contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
    contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
    contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
    //设置 自动换行
    contentWriteCellStyle.setWrapped(true);
    // 字体策略
    WriteFont contentWriteFont = new WriteFont();
    // 字体大小
    contentWriteFont.setFontHeightInPoints((short) 12);
    contentWriteCellStyle.setWriteFont(contentWriteFont);
    //头策略使用默认
    WriteCellStyle headWriteCellStyle = new WriteCellStyle();
 
    //excel如需下载到本地,只需要将response.getOutputStream()换成File即可(注释掉以上response代码)
    EasyExcel.write(response.getOutputStream(), PilebodycheckMonthDto.class)
            //设置输出excel版本,不设置默认为xlsx
            .excelType(ExcelTypeEnum.XLS).head(PilebodycheckMonthDto.class)
            //设置拦截器或自定义样式
            .registerWriteHandler(new MonthSheetWriteHandler())
            .registerWriteHandler(new HorizontalCellStyleStrategy(headWriteCellStyle,contentWriteCellStyle))
            .sheet("存量建筑垃圾堆体治理进度月报表")
            //设置默认样式及写入头信息开始的行数
            .useDefaultStyle(true).relativeHeadRowIndex(3)
            //这里的addsumColomn方法是个添加合计的方法,可删除
            .doWrite(pilebodycheckService.addSumColomn(pilebodysList));
    return new WebApiResponse(200, "生成excel文件成功", null);
 
}