新增excel读取工具类
This commit is contained in:
+48
@@ -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<List<String>> read(String filePath) {
|
||||
SimpleExcelListener listener = new SimpleExcelListener(filePath);
|
||||
ExcelReader excelReader = EasyExcelFactory.read(filePath, null, listener).headRowNumber(0).build();
|
||||
excelReader.readAll()
|
||||
List<List<String>> dataList = listener.getDataList();
|
||||
excelReader.finish()
|
||||
return dataList;
|
||||
}
|
||||
|
||||
class SimpleExcelListener extends AnalysisEventListener {
|
||||
|
||||
private List<List<String>> dataList = new ArrayList<>()
|
||||
|
||||
@Override
|
||||
void invoke(Object o, AnalysisContext analysisContext) {
|
||||
Map<String, String> map = o;
|
||||
dataList.add(new ArrayList<String>(map.values()))
|
||||
}
|
||||
|
||||
@Override
|
||||
void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
|
||||
}
|
||||
|
||||
List<List<String>> getDataList() {
|
||||
return dataList
|
||||
}
|
||||
|
||||
void setDataList(List<List<String>> dataList) {
|
||||
this.dataList = dataList
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user