package com.meteor.concurrent.excel;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet;
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern;
public class TestExcel { private static List<Entity> prepareData(){ List<Entity> list = new ArrayList<>(); for(int i = 0; i < 10; i++){ list.add(new Entity("name"+i,i+"",new Date())); } return list; } public static void write(List<Entity> res, String outputAddress) { ExcelWriter excelWriter = null; try { EasyExcel.write(outputAddress, Entity.class).sheet("测试").doWrite(res); } finally { if (excelWriter != null) { excelWriter.finish(); } } } public static void read(String inputAddress) throws FileNotFoundException { FileInputStream inputStream = new FileInputStream(inputAddress); List<Entity> test = EasyExcel.read(inputStream).head(Entity.class).sheet("测试").doReadSync(); test.stream().forEach(System.out::println); } public static void main(String[] args) throws FileNotFoundException { List<Entity> data = prepareData(); write(data,"D:\\test\\test.xlsx"); read("D:\\test\\test.xlsx"); } }
|