2022-07-26:easyExcel导出到excel

pom

<dependency> 

     <groupId>com.alibaba</groupId>                         <artifactId>easyexcel</artifactId>

     <version>3.0.5</version> 

</dependency>

3.0.5版本设置ExportExcelData 类中的边框设置使用BorderStyleEnum.THIN

EasyExcel导出 

定义导出类,并设置样式

import com.alibaba.excel.annotation.ExcelProperty;

import com.alibaba.excel.annotation.write.style.ColumnWidth;

import com.alibaba.excel.annotation.write.style.ContentStyle;

import com.alibaba.excel.annotation.write.style.HeadRowHeight;

import com.alibaba.excel.annotation.write.style.HeadStyle;

import lombok.Data;

import org.apache.poi.ss.usermodel.BorderStyle;

@Data

@ColumnWidth(25)

@HeadRowHeight(35)

@HeadStyle(fillForegroundColor =9)

@ContentStyle(

verticalAlignment = VerticalAlignmentEnum.CENTER,horizontalAlignment = HorizontalAlignmentEnum.CENTER,

borderTop = BorderStyleEnum.THIN,borderBottom = BorderStyleEnum.THIN,borderLeft = BorderStyleEnum.THIN,borderRight = BorderStyleEnum.THIN)

public class ExportExcelData {

@ExcelProperty("服务点")

private String fuwudian;

    @ExcelIgnore//设置不导出

private String code1;

    @ExcelIgnore//设置不导出

private String waybill;

    @ExcelProperty("寄件人姓名")

private String mail_name;

    @ExcelProperty("寄件人电话")

private String mail_phone;

    @ExcelProperty("寄件人地址")

private String mail_address;

    @ExcelProperty("收件人姓名")

private String addressee_name;

    @ExcelProperty("收件人电话")

private String addressee_phone;

    @ExcelProperty("收件人地址")

private String addressee_address;

    @ExcelProperty("物品信息")

private String goods;

    @ExcelProperty("物品重量")

private String weight;

    @ExcelProperty("订单号")

private String number;

    @ExcelProperty("价格")

private String final_money;

    @ExcelProperty("状态1")

private String state;

    @ExcelProperty("状态2")

private String state2;

}

导出接口 参数list:是需要自己在数据库中查询需要导出的数据

@RequestMapping("export")

public void export(HttpServletResponse response,List list){

    String fileName =new String("查询信息表.xlsx".getBytes(), StandardCharsets.ISO_8859_1);

    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

    response.setCharacterEncoding("utf-8");

    response.setHeader("Content-disposition", "attachment;filename=" + fileName);

try {

    EasyExcel.write(response.getOutputStream(), ExportExcelData.class).sheet("sheet").doWrite(list);

}catch (IOException e) {

    e.printStackTrace();

    throw new BusinessException(BusinessStatus.FAIL, "导出失败");

}

}


verticalAlignment = VerticalAlignmentEnum.CENTER,horizontalAlignment = HorizontalAlignmentEnum.CENTER,

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容