excel导入基于Easypoi一对多导入(实现合并单元格) |
您所在的位置:网站首页 › easypoi导入excel很慢 › excel导入基于Easypoi一对多导入(实现合并单元格) |
EasyPoi一对多导入
EasyPoi官方文档:(http://easypoi.mydoc.io/) 前言利用EasyPoi实现一对多的表格导入,主要注解@ExcelCollection 一、导入表格示例springboot整合EasyPoi cn.afterturn easypoi-spring-boot-starter 4.1.3 2.导入对应的实体@Excel:作用在字段上面,对应Excel的某一列的描述。 @ExcelCollection:集合,主要针对一对多的导出。 import cn.afterturn.easypoi.excel.annotation.Excel; import cn.afterturn.easypoi.excel.annotation.ExcelCollection; import lombok.Data; import java.util.List; @Data public class NewFunctionExcelVo { /** * 功能编号 */ @Excel(name = "一级功能编号", needMerge = true, width = 30) private String oneLevelNo; /** * 功能名称 */ @Excel(name = "一级功能", needMerge = true, width = 35) private String oneLevelName; @ExcelCollection(name = "子功能及描述") private List datChildrenFunction; } import cn.afterturn.easypoi.excel.annotation.Excel; import lombok.Data; @Data public class ChildrenExcelVo { @Excel(name = "二级功能编号", width = 35) private String twoLevelNo; @Excel(name = "二级功能", width = 35) private String twoLevelName; @Excel(name = "三级功能编号", width = 35) private String threeLevelNo; @Excel(name = "三级功能", width = 35) private String threeLevelName; @Excel(name = "四级功能编号", width = 35) private String fourLevelNo; @Excel(name = "四级功能", width = 35) private String fourLevelName; /** * 功能属性,关联数据字典“功能属性“ */ @Excel(name = "属性", width = 30) private String propertyName; /** * 说明 */ @Excel(name = "说明") private String support; /** * 描述 */ @Excel(name = "描述", width = 40) private String description; /** * 特性1 */ @Excel(name = "特性1", width = 40) private String exampleName; /** * 特性2 */ @Excel(name = "特性2", width = 40) private String service; } Test import cn.afterturn.easypoi.excel.ExcelImportUtil; import cn.afterturn.easypoi.excel.entity.ImportParams; import org.junit.Test; import java.io.FileInputStream; import java.util.List; public class test { @Test public void importQuestion() throws Exception { FileInputStream fis = new FileInputStream("D:\\测试文件.xlsx"); ImportParams params = new ImportParams(); params.setHeadRows(2); params.setTitleRows(0); List functionList = ExcelImportUtil.importExcel(fis, NewFunctionExcelVo.class, params); } } 导入最终数据结构
此前在网上也搜索了很多一对多的示例,导出的文章较多,并且不太符合本项目的需求,为此写了这篇又臭又长的博客供大家参考,导入导出最重要的就是实体类结合表格进行清楚明了的对应,其次结合EasyPoi注解,希望对大家有所帮助。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |