package com.example.demo.test; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import org.apache.poi.ss.usermodel.Workbook; import org.junit.Test; import java.io.File; import java.io.FileOutputStream; import java.util.*; public class TestExcel { public static void main(String[] args) throws Exception { //模拟从数据库获取需要导出的数据 ListpersonList = new ArrayList<>(); Person person1 = new Person("路飞","1",new Date()); Person person2 = new Person("娜美","2", new Date()); Person person3 = new Person("索隆","1", new Date()); Person person4 = new Person("小狸猫","1", new Date()); personList.add(person1); personList.add(person2); personList.add(person3); personList.add(person4); //导出操作 Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("计算机一班学生","学生"), Person .class, personList); FileOutputStream fos = new FileOutputStream("/Users/zhangmuqing/Desktop/test.xlsx"); workbook.write(fos); fos.close(); } @Test public void test1() throws Exception{ List studentList = new ArrayList<>(); StudentEntity person1 = new StudentEntity("111","张三0",1,new Date(),new Date()); StudentEntity person2 = new StudentEntity("111","张三2",2,new Date(),new Date()); StudentEntity person3 = new StudentEntity("111","张三1",1,new Date(),new Date()); StudentEntity person4 = new StudentEntity("111","张三3",2,new Date(),new Date()); studentList.add(person1); studentList.add(person2); studentList.add(person3); studentList.add(person4); List courselist = new ArrayList<>(); CourseEntity Course1 = new CourseEntity("1","老王0",new TeacherEntity("1","老王0"),studentList); CourseEntity Course2 = new CourseEntity("1","老王0",new TeacherEntity("1","老王0"),studentList); CourseEntity Course3 = new CourseEntity("1","老王0",new TeacherEntity("1","老王0"),studentList); CourseEntity Course4 = new CourseEntity("1","老王0",new TeacherEntity("1","老王0"),studentList); courselist.add(Course1); courselist.add(Course2); courselist.add(Course3); courselist.add(Course4); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("2412312", "测试", "测试"), CourseEntity.class, courselist); FileOutputStream fos = new FileOutputStream("/Users/zhangmuqing/Desktop/test4.xlsx"); workbook.write(fos); fos.close(); } @Test public void test2() throws Exception{ TemplateExportParams params = new TemplateExportParams( "src/main/resources/upload/test模板.xlsx"); Map map = new HashMap (); map.put("date", "2014-12-25"); map.put("money", 2000000.00); map.put("upperMoney", "贰佰万"); map.put("company", "执笔潜行科技有限公司"); map.put("bureau", "财政局"); map.put("person", "JueYue"); map.put("phone", "1879740****"); List
cn.afterturn easypoi-spring-boot-starter 3.3.0
springboot中以-spring-boot-starter就会自动导入相关的依赖jar包,不用一个一个去导入
}