写入:
File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "aa.csv"); ExcelWriter excelWriter = EasyExcelFactory.write(file).excelType(ExcelTypeEnum.CSV).charset(Charset.forName("GBK")) .build(); WriteSheet data = EasyExcelFactory.writerSheet("data").build(); ArrayList<String> strings = new ArrayList<>(); excelWriter.write(strings,data); excelWriter.finish();
public class ExcelListener extends AnalysisEventListener<UserData> { /** * 一行一行的读取excel内容 */ public void invoke(UserData data, AnalysisContext analysisContext) { System.out.println("****" + data); } /** * 读取表头内容 */ public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { System.out.println("表头" + headMap); } /** * 读取完成操作 */ public void doAfterAllAnalysed(AnalysisContext analysisContext) { System.out.println("读取Excel完毕"); } }
// 实现excel写操作 //1.设置写入文件夹地址和excel文件名称 String fileName = "/Users/zzs/temp/excel/write.xlsx"; //调用easyExcel里面的方法实现写操作 //2个参数,第一个参数是文件名称,第二个参数是实体类 EasyExcel.read(fileName, UserData.class, new ExcelListener()).sheet().doRead();
标签:读取,easyExcel,excel,System,public,csv,data,读写,out From: https://www.cnblogs.com/goPush/p/17418432.html