Skip to content

Commit

Permalink
Adding test case for colums without 'rel' attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
PJ Fanning committed Apr 6, 2019
1 parent 17efceb commit 88bc666
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ && isSpreadsheetTag(event.asStartElement().getName())) {

if(ref != null) {
String[] coord = splitCellRef(ref.getValue());
currentCell = new StreamingCell(currentRow, CellReference.convertColStringToIndex(coord[0]), Integer.parseInt(coord[1]) - 1, use1904Dates);
currentColNum = CellReference.convertColStringToIndex(coord[0]);
currentCell = new StreamingCell(currentRow, currentColNum, Integer.parseInt(coord[1]) - 1, use1904Dates);
} else {
currentCell = new StreamingCell(currentRow, currentColNum, currentRowNum, use1904Dates);
}
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/github/pjfanning/xlsx/StreamingReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -728,4 +728,26 @@ public void testFormulaWithDifferentTypes() throws Exception {
assertThat(cell.getCachedFormulaResultType(), is(CellType.NUMERIC));
}
}

@Test
public void testShouldIncrementColumnNumberIfExplicitCellAddressMissing() throws Exception {
// On consecutive columns the <c> element might miss an "r" attribute, which indicate the cell position.
// This might be an optimization triggered by file size and specific to a particular excel version.
// The excel would read such a file without complaining.
try(
InputStream is = new FileInputStream(new File("src/test/resources/sparse-columns.xlsx"));
Workbook wb = StreamingReader.builder().open(is);
) {
Sheet sheet = wb.getSheetAt(0);

Iterator<Row> rowIterator = sheet.rowIterator();
Row row = rowIterator.next();

assertThat(row.getCell(0).getStringCellValue(), is("sparse"));
assertThat(row.getCell(3).getStringCellValue(), is("columns"));
assertThat(row.getCell(4).getNumericCellValue(), is(0.0));
assertThat(row.getCell(5).getNumericCellValue(), is(1.0));

}
}
}
Binary file added src/test/resources/sparse-columns.xlsx
Binary file not shown.

0 comments on commit 88bc666

Please sign in to comment.