package excel; import org.junit.Test; import java.io.File; import java.io.IOException; import java.util.*; /** * Created by liangxianyou at 2018/7/6 10:29. */ public class ExportTest { @Test public void exportBean(){ Map heads = new LinkedHashMap(); heads.put("姓名", "name"); heads.put("年龄", "age"); int total = 5_0000; List rows = new ArrayList<>(total); Random random = new Random(); for (int i = 0; i < total; i++) { String name = UUID.randomUUID().toString(); int age = random.nextInt(100); rows.add(new Person(name, age)); } File file = new File("target/user.zip"); if (file.exists()) file.delete(); try { ExcelExportKit.exportExcelZip(heads, rows, file, ExcelExportKit.TC.BEAN); } catch (IOException e) { e.printStackTrace(); } } @Test public void exportMapToZip(){ Map heads = new LinkedHashMap(); heads.put("姓名", "name"); heads.put("姓名1", "name1"); heads.put("姓名2", "name2"); heads.put("年龄", "age"); int total = 5_0000; List rows = new ArrayList<>(total); Map r1 = new HashMap(); r1.put("name", "张三"); r1.put("age", 12); rows.add(r1); Random random = new Random(); //使用uuid 模拟复杂数据导出 for (int i = 0; i < total; i++) { Map r2 = new HashMap(); r2.put("name", UUID.randomUUID()); r2.put("name1", UUID.randomUUID()); r2.put("name2", UUID.randomUUID()); r2.put("age", random.nextInt(100)); rows.add(r2); } File file = new File("target/hello.zip"); if (file.exists()) file.delete(); try { ExcelExportKit.exportExcelZip(heads, rows, file, ExcelExportKit.TC.MAP); } catch (IOException e) { e.printStackTrace(); } } }