use of com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder in project easyexcel by alibaba.
the class SheetUtils method match.
/**
* Match the parameters to the actual sheet
*
* @param readSheet
* actual sheet
* @param analysisContext
* @return
*/
public static ReadSheet match(ReadSheet readSheet, AnalysisContext analysisContext) {
ReadWorkbookHolder readWorkbookHolder = analysisContext.readWorkbookHolder();
if (readWorkbookHolder.getReadAll()) {
return readSheet;
}
for (ReadSheet parameterReadSheet : readWorkbookHolder.getParameterSheetDataList()) {
if (parameterReadSheet == null) {
continue;
}
if (parameterReadSheet.getSheetNo() == null && parameterReadSheet.getSheetName() == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("The first is read by default.");
}
parameterReadSheet.setSheetNo(0);
}
boolean match = (parameterReadSheet.getSheetNo() != null && parameterReadSheet.getSheetNo().equals(readSheet.getSheetNo()));
if (!match) {
String parameterSheetName = parameterReadSheet.getSheetName();
if (!StringUtils.isEmpty(parameterSheetName)) {
boolean autoTrim = (parameterReadSheet.getAutoTrim() != null && parameterReadSheet.getAutoTrim()) || (parameterReadSheet.getAutoTrim() == null && analysisContext.readWorkbookHolder().getGlobalConfiguration().getAutoTrim());
if (autoTrim) {
parameterSheetName = parameterSheetName.trim();
}
match = parameterSheetName.equals(readSheet.getSheetName());
}
}
if (match) {
readSheet.copyBasicParameter(parameterReadSheet);
return readSheet;
}
}
return null;
}
use of com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder in project easyexcel by alibaba.
the class ExcelAnalyserImpl method finish.
@Override
public void finish() {
if (finished) {
return;
}
finished = true;
if (analysisContext == null || analysisContext.readWorkbookHolder() == null) {
return;
}
ReadWorkbookHolder readWorkbookHolder = analysisContext.readWorkbookHolder();
Throwable throwable = null;
try {
if (readWorkbookHolder.getReadCache() != null) {
readWorkbookHolder.getReadCache().destroy();
}
} catch (Throwable t) {
throwable = t;
}
try {
if ((readWorkbookHolder instanceof XlsxReadWorkbookHolder) && ((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage() != null) {
((XlsxReadWorkbookHolder) readWorkbookHolder).getOpcPackage().revert();
}
} catch (Throwable t) {
throwable = t;
}
try {
if ((readWorkbookHolder instanceof XlsReadWorkbookHolder) && ((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem() != null) {
((XlsReadWorkbookHolder) readWorkbookHolder).getPoifsFileSystem().close();
}
} catch (Throwable t) {
throwable = t;
}
// https://github.com/alibaba/easyexcel/issues/2309
try {
if ((readWorkbookHolder instanceof CsvReadWorkbookHolder) && ((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser() != null) {
((CsvReadWorkbookHolder) readWorkbookHolder).getCsvParser().close();
}
} catch (Throwable t) {
throwable = t;
}
try {
if (analysisContext.readWorkbookHolder().getAutoCloseStream() && readWorkbookHolder.getInputStream() != null) {
readWorkbookHolder.getInputStream().close();
}
} catch (Throwable t) {
throwable = t;
}
try {
if (readWorkbookHolder.getTempFile() != null) {
FileUtils.delete(readWorkbookHolder.getTempFile());
}
} catch (Throwable t) {
throwable = t;
}
clearEncrypt03();
removeThreadLocalCache();
if (throwable != null) {
throw new ExcelAnalysisException("Can not close IO.", throwable);
}
}
Aggregations