-
Notifications
You must be signed in to change notification settings - Fork 54k
[BAEL-6548] Determine empty row in Microsoft Excel #17479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BAEL-6548] Determine empty row in Microsoft Excel #17479
Conversation
| try (FileInputStream file = new FileInputStream(fileLocation); ReadableWorkbook wb = new ReadableWorkbook(file)) { | ||
| Sheet sheet = wb.getFirstSheet(); | ||
| try (Stream<Row> rows = sheet.openStream()) { | ||
| assertEquals(false, fastexcelHelper.isRowEmpty(rows.reduce((first, second) -> second).get())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertFalse ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reduce statement is a bit hard to understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed it as per the review comments.
| import org.dhatim.fastexcel.reader.Row; | ||
|
|
||
| public class FastexcelHelper { | ||
| public boolean isRowEmpty(Row row) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not formatted as per the standard. You're using tabs, where we should be using spaces.
| public class JExcelHelper { | ||
|
|
||
| public boolean isRowEmpty(Cell[] row) { | ||
| if (row == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using a mixture of tabs and spaces
| import jxl.read.biff.BiffException; | ||
|
|
||
|
|
||
| public class JExcelDetectEmptyRowUnitTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be formatted as per the standard - this uses tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please check.
| @Before | ||
| public void loadExcelFile() throws IOException { | ||
|
|
||
| fileLocation = "src/main/resources/" + FILE_NAME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to be initialized this way. fileLocation always has the same value and so should be private static final String FILE_LOCATION initialized in the class' static initializer list
| private static final String SHEET_NAME = "Sheet1"; | ||
|
|
||
| @Test | ||
| public void givenExcelFileWithXLSXFormat_whenGetColumnNames_thenReturnsColumnNames() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformat with spaces
| public void whenParsingFastExcelFile_thenDetectEmptyRow() throws IOException { | ||
| try (FileInputStream file = new FileInputStream(fileLocation); ReadableWorkbook wb = new ReadableWorkbook(file)) { | ||
| Sheet sheet = wb.getFirstSheet(); | ||
| try (Stream<Row> rows = sheet.openStream()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this implementation not possible?
// assert all rows are empty
try (Stream<Row> rows = sheet.openStream()) {
boolean isEmpty = rows.allMatch(fastexcelHelper::isRowEmpty);
assertTrue(isEmpty);
}
// assert last row is empty
try (Stream<Row> rows = sheet.openStream()) {
Optional<Row> last = rows.reduce((first, second) -> second);
boolean isLastRowEmpty = last.map(fastexcelHelper::isRowEmpty).orElseThrow();
assertTrue(isLastRowEmpty);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I added test cases for an empty file and a file with a few records but empty rows.
Added the code and tests for checking if the row is empty using the following libraries:
Test cases for each of the library with a file containing a few records and an empty file.