Excel导入导出(pojo和测试用例)

Excel工具类_今天早睡哦的博客-CSDN博客

public class TestExportEntity {
    @Excel(name = "姓名")
    private String name;
    @Excel(name = "年龄")
    private Integer age;
    @Excel(name = "性别", replace = {"男_true,女_false"})
    private Boolean sex;
    @Excel(name = "住址")
    private String addr;

    public TestExportEntity() {
    }

    public TestExportEntity(String name, Integer age, Boolean sex, String addr) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        this.addr = addr;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Boolean getSex() {
        return sex;
    }

    public void setSex(Boolean sex) {
        this.sex = sex;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }
}


/**
*  导入
*/
    public void leadingInExcel(MultipartFile excelFile) {
        try {
            ExcelUtils.importExcel(excelFile, 0, 1, InvoiceExportEntity.class);
        } catch (IOException e) {
            throw new BizException("导入失败");
        }
    }
 /**
*导出excel
*/

@RequestMapping("export")
    public void export(HttpServletResponse response) throws IOException {
        List> list = new ArrayList<>();

        List exportEntities = new ArrayList<>();
        exportEntities.add(new TestExportEntity("joii", 28, Boolean.TRUE, "浙江"));

        list.add(Maps.of("title", new ExportParams(), "entity", TestExportEntity.class, "data", exportEntities));

        ExcelUtils.exportExcel(list, "测试导出", response);
    }

你可能感兴趣的:(测试用例)