Move to next sheet when there are only empty/invalid rows (#82)
When there are blank or empty lines in the end of one sheet, null is returned by doRead without trying to read next sheet. A recursive call makes sheet moving happen when another exists. Co-authored-by: Mahmoud Ben Hassine <mbenhassine@vmware.com> Co-authored-by: cesar.alves@gmail.com <coa@pc-coa.caso.pt>
This commit is contained in:
@@ -107,7 +107,7 @@ public abstract class AbstractExcelItemReader<T> extends AbstractItemCountingIte
|
||||
this.rs.next();
|
||||
}
|
||||
try {
|
||||
return (this.rs.getCurrentRow() != null) ? this.rowMapper.mapRow(this.rs) : null;
|
||||
return (this.rs.getCurrentRow() != null) ? this.rowMapper.mapRow(this.rs) : doRead();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new ExcelFileParseException("Exception parsing Excel file.", ex, this.resource.getDescription(),
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.extensions.excel.poi;
|
||||
|
||||
import org.springframework.batch.extensions.excel.AbstractExcelItemReader;
|
||||
import org.springframework.batch.extensions.excel.AbstractExcelItemReaderTests;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
* @author Marten Deinum
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public class PoiItemReaderXlsWithBlankLinesTests extends AbstractExcelItemReaderTests {
|
||||
|
||||
@Override
|
||||
protected void configureItemReader(AbstractExcelItemReader<String[]> itemReader) {
|
||||
itemReader.setResource(new ClassPathResource("player_with_blank_lines.xls"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractExcelItemReader<String[]> createExcelItemReader() {
|
||||
return new PoiItemReader<>();
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user