public class TestEasyExcel {
public static void main(String[] args) throws Exception {
String filepath = "D:/LDT/测试easyExcel.xlsx";
Sheet sheet = new Sheet(1, 0);
sheet.setSheetName("xxxx");
List<List<String>> header = new ArrayList<List<String>>();
header.add(Lists.newArrayList("Number"));
header.add(Lists.newArrayList("Name"));
header.add(Lists.newArrayList("Age"));
sheet.setHead(header);
List<List<Object>> data = new ArrayList<List<Object>>();
data.add(Lists.newArrayList("1001","Zhangsan",13));
data.add(Lists.newArrayList("1002","Lisi",23));
data.add(Lists.newArrayList("1003","Wangwu",33));
OutputStream out = new FileOutputStream(new File(filepath));
ExcelWriter writer = EasyExcelFactory.getWriter(out, ExcelTypeEnum.XLSX, true);
System.out.println(writer);
writer.write1(data, sheet);
writer.finish();
}
}
Error message: org.apache.poi.ss.usermodel.font.setbold (z) V
Cause: there is a conflict between Maven version and poi jar package. The following is Maven version. If POI version is 3.8 or 3.9, this exception message will appear.
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>1.1.2-beta4</version>
</dependency>
Solution: this exception will not occur in version 3.17 and above.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
</dependency>