forked from fanruan/easyexcel
zhuangjiaju
5 years ago
53 changed files with 1406 additions and 1137 deletions
@ -1,112 +0,0 @@
|
||||
package com.alibaba.excel.analysis; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Map.Entry; |
||||
|
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.converters.ConverterKey; |
||||
import com.alibaba.excel.converters.ConverterRegistryCenter; |
||||
import com.alibaba.excel.converters.DefaultConverterLoader; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.excel.event.AnalysisEventRegistryCenter; |
||||
import com.alibaba.excel.event.AnalysisFinishEvent; |
||||
import com.alibaba.excel.metadata.property.ExcelHeadProperty; |
||||
import com.alibaba.excel.metadata.Sheet; |
||||
|
||||
/** |
||||
* @author jipengfei |
||||
*/ |
||||
public abstract class BaseSaxAnalyser implements ConverterRegistryCenter, AnalysisEventRegistryCenter, ExcelAnalyser { |
||||
|
||||
protected AnalysisContext analysisContext; |
||||
|
||||
private LinkedHashMap<String, AnalysisEventListener<Object>> listeners = |
||||
new LinkedHashMap<String, AnalysisEventListener<Object>>(); |
||||
|
||||
private Map<ConverterKey, Converter> converters = new HashMap<ConverterKey, Converter>(); |
||||
|
||||
/** |
||||
* execute method |
||||
*/ |
||||
protected abstract void execute(); |
||||
|
||||
@Override |
||||
public void register(String name, AnalysisEventListener<Object> listener) { |
||||
if (!listeners.containsKey(name)) { |
||||
listeners.put(name, listener); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void register(Converter converter) { |
||||
converters.put(new ConverterKey(converter.supportJavaTypeKey(),converter.supportExcelTypeKey()), converter); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeAnalysis() { |
||||
registerDefaultConverters(); |
||||
} |
||||
|
||||
private void registerDefaultConverters() { |
||||
converters.putAll(DefaultConverterLoader.loadDefaultReadConverter()); |
||||
} |
||||
|
||||
@Override |
||||
public Map<ConverterKey, Converter> getConverters() { |
||||
return converters; |
||||
} |
||||
|
||||
@Override |
||||
public void analysis(Sheet sheetParam) { |
||||
analysisContext.setCurrentSheet(sheetParam); |
||||
execute(); |
||||
} |
||||
|
||||
@Override |
||||
public void analysis() { |
||||
execute(); |
||||
} |
||||
|
||||
@Override |
||||
public AnalysisContext getAnalysisContext() { |
||||
return analysisContext; |
||||
} |
||||
|
||||
/** |
||||
*/ |
||||
@Override |
||||
public void cleanAllListeners() { |
||||
listeners.clear(); |
||||
} |
||||
|
||||
@Override |
||||
public void cleanListener(String name) { |
||||
listeners.remove(name); |
||||
} |
||||
|
||||
@SuppressWarnings("unchecked") |
||||
@Override |
||||
public void notify(AnalysisFinishEvent event) { |
||||
analysisContext.setCurrentRowAnalysisResult(event.getAnalysisResult()); |
||||
/** Parsing header content **/ |
||||
if (analysisContext.getCurrentRowNum() < analysisContext.getCurrentSheet().getReadHeadRowNumber()) { |
||||
if (analysisContext.getCurrentRowNum() <= analysisContext.getCurrentSheet().getReadHeadRowNumber() - 1) { |
||||
buildExcelHeadProperty(null, (List<String>)analysisContext.getCurrentRowAnalysisResult()); |
||||
} |
||||
} else { |
||||
for (Entry<String, AnalysisEventListener<Object>> entry : listeners.entrySet()) { |
||||
entry.getValue().invoke(analysisContext.getCurrentRowAnalysisResult(), analysisContext); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void buildExcelHeadProperty(Class clazz, List<String> headOneRow) { |
||||
ExcelHeadProperty excelHeadProperty = |
||||
ExcelHeadProperty.buildExcelHeadProperty(this.analysisContext.getExcelHeadProperty(), clazz, headOneRow); |
||||
this.analysisContext.setExcelHeadProperty(excelHeadProperty); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.alibaba.excel.analysis; |
||||
|
||||
import java.util.List; |
||||
|
||||
import com.alibaba.excel.metadata.Sheet; |
||||
|
||||
/** |
||||
* Excel file Executor |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public interface ExcelExecutor { |
||||
|
||||
List<Sheet> sheetList(); |
||||
|
||||
void execute(); |
||||
|
||||
} |
@ -1,27 +0,0 @@
|
||||
package com.alibaba.excel.cache; |
||||
|
||||
/** |
||||
* cache |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public interface Cache { |
||||
|
||||
/** |
||||
* put |
||||
* |
||||
* @param key |
||||
* @param value |
||||
*/ |
||||
void put(Integer key, String value); |
||||
|
||||
/** |
||||
* get |
||||
* |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
String get(Integer key); |
||||
|
||||
void finish(); |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.alibaba.excel.cache; |
||||
|
||||
/** |
||||
* Read cache |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public interface ReadCache { |
||||
/** |
||||
* Automatically generate the key and put it in the cache.Key start from 0 |
||||
* |
||||
* @param value |
||||
*/ |
||||
void put(String value); |
||||
|
||||
/** |
||||
* Get |
||||
* |
||||
* @param key |
||||
* @return |
||||
*/ |
||||
String get(Integer key); |
||||
|
||||
/** |
||||
* 所有 |
||||
*/ |
||||
void putFinished(); |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
void destroy(); |
||||
|
||||
} |
@ -1,176 +1,47 @@
|
||||
package com.alibaba.excel.context; |
||||
|
||||
import java.io.InputStream; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import com.alibaba.excel.converters.ConverterRegistryCenter; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.excel.exception.ExcelAnalysisException; |
||||
import com.alibaba.excel.metadata.property.ExcelHeadProperty; |
||||
import com.alibaba.excel.metadata.Sheet; |
||||
import com.alibaba.excel.support.ExcelTypeEnum; |
||||
import com.alibaba.excel.metadata.holder.SheetHolder; |
||||
import com.alibaba.excel.metadata.holder.WorkbookHolder; |
||||
|
||||
/** |
||||
* |
||||
* @author jipengfei |
||||
*/ |
||||
public class AnalysisContextImpl implements AnalysisContext { |
||||
|
||||
private Object custom; |
||||
|
||||
private Sheet currentSheet; |
||||
|
||||
private ExcelTypeEnum excelType; |
||||
|
||||
private InputStream inputStream; |
||||
|
||||
private AnalysisEventListener<Object> eventListener; |
||||
|
||||
private Integer currentRowNum; |
||||
|
||||
private Integer totalCount; |
||||
|
||||
private ExcelHeadProperty excelHeadProperty; |
||||
|
||||
private boolean trim; |
||||
|
||||
private boolean use1904WindowDate = false; |
||||
|
||||
private ConverterRegistryCenter converterRegistryCenter; |
||||
|
||||
@Override |
||||
public void setUse1904WindowDate(boolean use1904WindowDate) { |
||||
this.use1904WindowDate = use1904WindowDate; |
||||
} |
||||
|
||||
@Override |
||||
public Object getCurrentRowAnalysisResult() { |
||||
return currentRowAnalysisResult; |
||||
} |
||||
|
||||
@Override |
||||
public void interrupt() { |
||||
throw new ExcelAnalysisException("interrupt error"); |
||||
} |
||||
|
||||
@Override |
||||
public boolean use1904WindowDate() { |
||||
return use1904WindowDate; |
||||
} |
||||
|
||||
@Override |
||||
public void setCurrentRowAnalysisResult(Object currentRowAnalysisResult) { |
||||
this.currentRowAnalysisResult = currentRowAnalysisResult; |
||||
} |
||||
|
||||
private Object currentRowAnalysisResult; |
||||
|
||||
public AnalysisContextImpl(InputStream inputStream, ExcelTypeEnum excelTypeEnum, Object custom, |
||||
AnalysisEventListener<Object> listener, ConverterRegistryCenter converterRegistryCenter, boolean trim) { |
||||
this.custom = custom; |
||||
this.eventListener = listener; |
||||
this.inputStream = inputStream; |
||||
this.excelType = excelTypeEnum; |
||||
this.trim = trim; |
||||
this.converterRegistryCenter = converterRegistryCenter; |
||||
} |
||||
|
||||
@Override |
||||
public void setCurrentSheet(Sheet currentSheet) { |
||||
cleanCurrentSheet(); |
||||
this.currentSheet = currentSheet; |
||||
if (currentSheet.getClazz() != null) { |
||||
excelHeadProperty = |
||||
ExcelHeadProperty.buildExcelHeadProperty(this.excelHeadProperty, currentSheet.getClazz(), null); |
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AnalysisContextImpl.class); |
||||
/** |
||||
* The Workbook currently written |
||||
*/ |
||||
private WorkbookHolder currentWorkbookHolder; |
||||
/** |
||||
* Current sheet holder |
||||
*/ |
||||
private SheetHolder currentSheetHolder; |
||||
|
||||
public AnalysisContextImpl(com.alibaba.excel.metadata.Workbook workbook) { |
||||
if (workbook == null) { |
||||
throw new IllegalArgumentException("Workbook argument cannot be null"); |
||||
} |
||||
currentWorkbookHolder = WorkbookHolder.buildReadWorkbookHolder(workbook); |
||||
if (LOGGER.isDebugEnabled()) { |
||||
LOGGER.debug("Initialization 'AnalysisContextImpl' complete"); |
||||
} |
||||
} |
||||
|
||||
|
||||
private void cleanCurrentSheet() { |
||||
this.currentSheet = null; |
||||
this.excelHeadProperty = null; |
||||
this.totalCount = 0; |
||||
this.currentRowAnalysisResult = null; |
||||
this.currentRowNum =0; |
||||
} |
||||
|
||||
@Override |
||||
public ExcelTypeEnum getExcelType() { |
||||
return excelType; |
||||
} |
||||
|
||||
public void setExcelType(ExcelTypeEnum excelType) { |
||||
this.excelType = excelType; |
||||
} |
||||
|
||||
public Object getCustom() { |
||||
return custom; |
||||
} |
||||
|
||||
public void setCustom(Object custom) { |
||||
this.custom = custom; |
||||
} |
||||
|
||||
@Override |
||||
public Sheet getCurrentSheet() { |
||||
return currentSheet; |
||||
} |
||||
|
||||
@Override |
||||
public InputStream getInputStream() { |
||||
return inputStream; |
||||
} |
||||
|
||||
public void setInputStream(InputStream inputStream) { |
||||
this.inputStream = inputStream; |
||||
} |
||||
|
||||
@Override |
||||
public AnalysisEventListener<Object> getEventListener() { |
||||
return eventListener; |
||||
} |
||||
|
||||
public void setEventListener(AnalysisEventListener<Object> eventListener) { |
||||
this.eventListener = eventListener; |
||||
} |
||||
|
||||
@Override |
||||
public Integer getCurrentRowNum() { |
||||
return this.currentRowNum; |
||||
} |
||||
|
||||
@Override |
||||
public void setCurrentRowNum(Integer row) { |
||||
this.currentRowNum = row; |
||||
} |
||||
|
||||
@Override |
||||
public Integer getTotalCount() { |
||||
return totalCount; |
||||
} |
||||
|
||||
@Override |
||||
public void setTotalCount(Integer totalCount) { |
||||
this.totalCount = totalCount; |
||||
} |
||||
|
||||
@Override |
||||
public ExcelHeadProperty getExcelHeadProperty() { |
||||
return this.excelHeadProperty; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void setExcelHeadProperty(ExcelHeadProperty excelHeadProperty) { |
||||
this.excelHeadProperty = excelHeadProperty; |
||||
} |
||||
|
||||
@Override |
||||
public boolean trim() { |
||||
return this.trim; |
||||
} |
||||
|
||||
@Override |
||||
public ConverterRegistryCenter getConverterRegistryCenter() { |
||||
return converterRegistryCenter; |
||||
public void currentSheet(com.alibaba.excel.metadata.Sheet sheet) { |
||||
if (sheet == null) { |
||||
throw new IllegalArgumentException("Sheet argument cannot be null"); |
||||
} |
||||
if (sheet.getSheetNo() == null || sheet.getSheetNo() <= 0) { |
||||
sheet.setSheetNo(0); |
||||
} |
||||
currentSheetHolder = SheetHolder.buildReadWorkSheetHolder(sheet, currentWorkbookHolder); |
||||
if (LOGGER.isDebugEnabled()) { |
||||
LOGGER.debug("Began to read:{}", sheet); |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,9 +0,0 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.Map; |
||||
|
||||
public interface ConverterRegistryCenter { |
||||
void register(Converter converter); |
||||
Map<ConverterKey, Converter> getConverters(); |
||||
} |
@ -1,35 +0,0 @@
|
||||
package com.alibaba.excel.event; |
||||
|
||||
/** |
||||
* Event center. |
||||
* |
||||
* @author jipengfei |
||||
*/ |
||||
public interface AnalysisEventRegistryCenter { |
||||
|
||||
/** |
||||
* Append listener |
||||
* |
||||
* @param name listener name. |
||||
* @param listener Callback method after each row is parsed. |
||||
*/ |
||||
void register(String name, AnalysisEventListener<Object> listener); |
||||
|
||||
/** |
||||
* Parse one row to notify all event listeners |
||||
* |
||||
* @param event parse event |
||||
*/ |
||||
void notify(AnalysisFinishEvent event); |
||||
|
||||
/** |
||||
* Clean all listeners. |
||||
*/ |
||||
void cleanAllListeners(); |
||||
|
||||
/** |
||||
* clean listener by name |
||||
* @param name the listener name |
||||
*/ |
||||
void cleanListener(String name); |
||||
} |
@ -1,81 +0,0 @@
|
||||
package com.alibaba.excel.event; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.converters.ConverterKey; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.exception.ExcelDataConvertException; |
||||
import com.alibaba.excel.exception.ExcelGenerateException; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||
import com.alibaba.excel.metadata.property.ExcelHeadProperty; |
||||
|
||||
import net.sf.cglib.beans.BeanMap; |
||||
|
||||
/** |
||||
* @author jipengfei |
||||
*/ |
||||
public class ModelBuildEventListener extends AnalysisEventListener<Object> { |
||||
private final Map<ConverterKey, Converter> converters; |
||||
|
||||
public ModelBuildEventListener(Map<ConverterKey, Converter> converters) { |
||||
this.converters = converters; |
||||
} |
||||
|
||||
@Override |
||||
public void invoke(Object object, AnalysisContext context) { |
||||
if (context.getExcelHeadProperty() != null && context.getExcelHeadProperty().getHeadClazz() != null) { |
||||
try { |
||||
@SuppressWarnings("unchecked") |
||||
Object resultModel = buildUserModel(context, (List<CellData>)object); |
||||
context.setCurrentRowAnalysisResult(resultModel); |
||||
} catch (Exception e) { |
||||
throw new ExcelGenerateException(e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"}) |
||||
private Object buildUserModel(AnalysisContext context, List<CellData> cellDataList) throws Exception { |
||||
ExcelHeadProperty excelHeadProperty = context.getExcelHeadProperty(); |
||||
Object resultModel = excelHeadProperty.getHeadClazz().newInstance(); |
||||
Map<String,Object> map = new HashMap<String,Object>(); |
||||
for (int i = 0; i < cellDataList.size(); i++) { |
||||
ExcelContentProperty contentProperty = excelHeadProperty.getContentPropertyMap().get(i); |
||||
if (contentProperty != null) { |
||||
CellData cellData = cellDataList.get(i); |
||||
if (cellData.getType() == CellDataTypeEnum.EMPTY) { |
||||
continue; |
||||
} |
||||
Object value = convertValue(cellDataList.get(i), contentProperty.getField().getClass(), contentProperty); |
||||
if (value != null) { |
||||
map.put(contentProperty.getField().getName(), value); |
||||
} |
||||
} |
||||
} |
||||
BeanMap.create(resultModel).putAll(map); |
||||
return resultModel; |
||||
} |
||||
|
||||
private Object convertValue(CellData cellData, Class clazz, ExcelContentProperty contentProperty) { |
||||
Converter converter = converters.get(ConverterKey.buildConverterKey(clazz, cellData.getType())); |
||||
if (converter == null) { |
||||
throw new ExcelDataConvertException( |
||||
"Converter not found, convert " + cellData.getType() + " to " + clazz.getName()); |
||||
} |
||||
try { |
||||
return converter.convertToJavaData(cellData, contentProperty); |
||||
} catch (Exception e) { |
||||
throw new ExcelDataConvertException("Convert data " + cellData + " to " + clazz + " error ", e); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void doAfterAllAnalysed(AnalysisContext context) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.alibaba.excel.metadata.holder; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.converters.ConverterKey; |
||||
import com.alibaba.excel.metadata.property.ExcelHeadProperty; |
||||
import com.alibaba.excel.read.listener.ReadListener; |
||||
|
||||
/** |
||||
* |
||||
* Get the corresponding configuration |
||||
* |
||||
* @author zhuangjiaju |
||||
**/ |
||||
public interface ReadConfiguration { |
||||
/** |
||||
* What handler does the currently operated cell need to execute |
||||
* |
||||
* @return |
||||
*/ |
||||
List<ReadListener> readListenerList(); |
||||
|
||||
/** |
||||
* What converter does the currently operated cell need to execute |
||||
* |
||||
* @return |
||||
*/ |
||||
Map<ConverterKey, Converter> readConverterMap(); |
||||
|
||||
/** |
||||
* What 'ExcelHeadProperty' does the currently operated cell need to execute |
||||
* |
||||
* @return |
||||
*/ |
||||
ExcelHeadProperty excelHeadProperty(); |
||||
|
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.alibaba.excel.read.builder; |
||||
|
||||
import com.alibaba.excel.metadata.Workbook; |
||||
|
||||
/** |
||||
* Build ExcelWriter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ExcelReaderBuilder { |
||||
/** |
||||
* Workbook |
||||
*/ |
||||
private Workbook workbook; |
||||
|
||||
public ExcelReaderBuilder() { |
||||
this.workbook = new Workbook(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,98 @@
|
||||
package com.alibaba.excel.read.listener; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.converters.ConverterKey; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.enums.HeadKindEnum; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.excel.exception.ExcelDataConvertException; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.Head; |
||||
import com.alibaba.excel.metadata.holder.ReadConfiguration; |
||||
import com.alibaba.excel.metadata.property.ExcelContentProperty; |
||||
import com.alibaba.excel.metadata.property.ExcelHeadProperty; |
||||
|
||||
import net.sf.cglib.beans.BeanMap; |
||||
|
||||
/** |
||||
* Convert to the object the user needs |
||||
* |
||||
* @author jipengfei |
||||
*/ |
||||
public class ModelBuildEventListener extends AnalysisEventListener<List<CellData>> { |
||||
@Override |
||||
public void onException(Exception exception, AnalysisContext context) throws Exception {} |
||||
|
||||
@Override |
||||
public void invoke(List<CellData> data, AnalysisContext context) { |
||||
ReadConfiguration readConfiguration = context.currentConfiguration(); |
||||
if (HeadKindEnum.CLASS.equals(context.currentSheetHolder().getExcelHeadProperty().getHeadKind())) { |
||||
context.setCurrentRowAnalysisResult(buildUserModel(data, readConfiguration)); |
||||
return; |
||||
} |
||||
context.setCurrentRowAnalysisResult(buildStringList(data, readConfiguration)); |
||||
} |
||||
|
||||
private Object buildStringList(List<CellData> data, ReadConfiguration readConfiguration) { |
||||
List<String> list = new ArrayList<String>(); |
||||
for (CellData cellData : data) { |
||||
list.add((String)convertValue(cellData, String.class, null, readConfiguration.readConverterMap())); |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
private Object buildUserModel(List<CellData> data, ReadConfiguration readConfiguration) { |
||||
ExcelHeadProperty excelHeadProperty = readConfiguration.excelHeadProperty(); |
||||
Object resultModel; |
||||
try { |
||||
resultModel = excelHeadProperty.getHeadClazz().newInstance(); |
||||
} catch (Exception e) { |
||||
throw new ExcelDataConvertException("Can not instance class: " + excelHeadProperty.getHeadClazz().getName(), |
||||
e); |
||||
} |
||||
Map<String, Object> map = new HashMap<String, Object>(); |
||||
Map<Integer, Head> headMap = excelHeadProperty.getHeadMap(); |
||||
Map<Integer, ExcelContentProperty> contentPropertyMap = excelHeadProperty.getContentPropertyMap(); |
||||
for (Map.Entry<Integer, Head> entry : headMap.entrySet()) { |
||||
Integer index = entry.getKey(); |
||||
if (index >= data.size()) { |
||||
continue; |
||||
} |
||||
CellData cellData = data.get(index); |
||||
if (cellData.getType() == CellDataTypeEnum.EMPTY) { |
||||
continue; |
||||
} |
||||
ExcelContentProperty excelContentProperty = contentPropertyMap.get(index); |
||||
Object value = convertValue(cellData, excelContentProperty.getField().getClass(), excelContentProperty, |
||||
readConfiguration.readConverterMap()); |
||||
if (value != null) { |
||||
map.put(excelContentProperty.getField().getName(), value); |
||||
} |
||||
} |
||||
BeanMap.create(resultModel).putAll(map); |
||||
return resultModel; |
||||
} |
||||
|
||||
private Object convertValue(CellData cellData, Class clazz, ExcelContentProperty contentProperty, |
||||
Map<ConverterKey, Converter> readConverterMap) { |
||||
Converter converter = readConverterMap.get(ConverterKey.buildConverterKey(clazz, cellData.getType())); |
||||
if (converter == null) { |
||||
throw new ExcelDataConvertException( |
||||
"Converter not found, convert " + cellData.getType() + " to " + clazz.getName()); |
||||
} |
||||
try { |
||||
return converter.convertToJavaData(cellData, contentProperty); |
||||
} catch (Exception e) { |
||||
throw new ExcelDataConvertException("Convert data " + cellData + " to " + clazz + " error ", e); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void doAfterAllAnalysed(AnalysisContext context) {} |
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.excel.read.listener; |
||||
|
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.excel.event.AnalysisFinishEvent; |
||||
|
||||
/** |
||||
* Registry center. |
||||
* |
||||
* @author jipengfei |
||||
*/ |
||||
public interface ReadListenerRegistryCenter { |
||||
|
||||
/** |
||||
* register |
||||
* |
||||
* @param listener |
||||
*/ |
||||
void register(AnalysisEventListener listener); |
||||
|
||||
/** |
||||
* Parse one row to notify all event listeners |
||||
* |
||||
* @param event |
||||
* parse event |
||||
* @param analysisContext |
||||
*/ |
||||
void notifyEndOneRow(AnalysisFinishEvent event, AnalysisContext analysisContext); |
||||
|
||||
/** |
||||
* |
||||
* @param analysisContext |
||||
*/ |
||||
void notifyAfterAllAnalysed(AnalysisContext analysisContext); |
||||
} |
Loading…
Reference in new issue