From 37c2ee5c89681e975cf034e790749e33b9ba110d Mon Sep 17 00:00:00 2001 From: sjshenjian Date: Thu, 1 Jul 2021 18:19:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eexcel=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/util/ExcelUtils.groovy | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy new file mode 100644 index 000000000..229499b80 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/ExcelUtils.groovy @@ -0,0 +1,48 @@ +package com.fangjia.script.temp.shenjian.util + +import com.alibaba.excel.EasyExcelFactory +import com.alibaba.excel.ExcelReader +import com.alibaba.excel.context.AnalysisContext +import com.alibaba.excel.event.AnalysisEventListener + +/** + * excel¹¤¾ßÀà + * + * @author shenjian + * @since 2021/5/15 + */ +class ExcelUtils { + + static List> read(String filePath) { + SimpleExcelListener listener = new SimpleExcelListener(filePath); + ExcelReader excelReader = EasyExcelFactory.read(filePath, null, listener).headRowNumber(0).build(); + excelReader.readAll() + List> dataList = listener.getDataList(); + excelReader.finish() + return dataList; + } + + class SimpleExcelListener extends AnalysisEventListener { + + private List> dataList = new ArrayList<>() + + @Override + void invoke(Object o, AnalysisContext analysisContext) { + Map map = o; + dataList.add(new ArrayList(map.values())) + } + + @Override + void doAfterAllAnalysed(AnalysisContext analysisContext) { + + } + + List> getDataList() { + return dataList + } + + void setDataList(List> dataList) { + this.dataList = dataList + } + } +}