1. Introduction of POM
<dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-base</artifactId> <version>3.0.3</version> </dependency> <dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-web</artifactId> <version>3.0.3</version> </dependency> <dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-annotation</artifactId> <version>3.0.3</version> </dependency>
Second, excel file export
2.1 Physical Design
public class Sku { @Excel(name = "skuNo",orderNum="0") private String skuNo; @Excel(name = "soldTo",orderNum="1") private String soldTo; @Excel(name = "hubId",orderNum="2") private String hubId; @Excel(name = "soldAllocation",orderNum="3") private String soldAllocation; @Excel(name = "hubAllocation",orderNum="4") private String hubAllocation;
Add a comment to the field that needs to be generated to excel, and then set num, starting from 0
@Excel(name = "生日", orderNum = "8", importFormat = "yyyy-MM-dd")
2.2 Export
@Test public void test() throws Exception{ List<Sku> list = new ArrayList<>(); for (int i=1; i<10000; i++) { Sku s = new Sku (); s.setHubAllocation("hubAllocation" + i); s.setHubId("hubId" + i); s.setSkuNo("skuNo"+ i); s.setSoldAllocation("soldAllocation" + i); s.setSoldTo("soldTo"+ i); list.add(s); } Date start = new Date(); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), Sku.class, list); System.out.println(new Date().getTime() - start.getTime()); File savefile = new File("D:/excel/"); if (!savefile.exists()) { savefile.mkdirs(); } FileOutputStream fos = new FileOutputStream("D:/excel/SKU.xlsx"); workbook.write(fos); fos.close(); }
2.3 Test Results
3. Import and parse the file into the database
3.1 Physical Design
public class Sku { @Excel(name = "skuNo") private String skuNo; @Excel(name = "soldTo") private String soldTo; @Excel(name = "hubId") private String hubId; @Excel(name = "soldAllocation") private String soldAllocation; @Excel(name = "hubAllocation") private String hubAllocation;
Description: Import does not need to specify num column number
3.2 Import
@Test public void test2() { ImportParams params = new ImportParams(); params.setTitleRows(0); params.setHeadRows(1); long start = new Date().getTime(); List<Sku> list = ExcelImportUtil.importExcel( new File("D:/excel/SKU.xlsx"), Sku.class, params); System.out.println(new Date().getTime() - start); System.out.println(list.size()); }
Description: setTitleRows(0) sets the position of the column title, such as
rows should be set to 0
Official document location:
http://easypoi.mydoc.io/#text_197818