easypoi 작업word와 excel

5135 단어 IO
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 {

        // 
        List personList = 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> listMap = new ArrayList>();
        for (int i = 0; i < 4; i++) {
            Map lm = new HashMap();
            lm.put("id", i + 1 + "");
            lm.put("zijin", i * 10000 + "");
            lm.put("bianma", "A001");
            lm.put("mingcheng", " ");
            lm.put("xiangmumingcheng", "EasyPoi " + i + " ");
            lm.put("quancheng", " ");
            lm.put("sqje", i * 10000 + "");
            lm.put("hdje", i * 10000 + "");

            listMap.add(lm);
        }
        map.put("maplist", listMap);

        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        File savefile = new File("/Users/zhangmuqing/Desktop/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream("/Users/zhangmuqing/Desktop/ _map.xlsx");
        workbook.write(fos);
        fos.close();





    }




    cn.afterturn
    easypoi-spring-boot-starter
    3.3.0

 
springboot에서 -spring-boot-starter로 관련 의존jar 패키지를 자동으로 가져옵니다. 하나씩 가져오지 않아도 됩니다.

}

좋은 웹페이지 즐겨찾기