Skip to content

Commit

Permalink
Fix for #85, adding null check for MissingCellPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
monitorjbl committed Apr 23, 2017
1 parent b517261 commit cfb078c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/main/java/com/monitorjbl/xlsx/impl/StreamingRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ public short getFirstCellNum() {
return cellMap.firstKey().shortValue();
}

/**
* {@inheritDoc}
*/
@Override
public Cell getCell(int cellnum, MissingCellPolicy policy) {
StreamingCell cell = (StreamingCell) cellMap.get(cellnum);
if(policy == MissingCellPolicy.CREATE_NULL_AS_BLANK) {
if(cell == null) { return new StreamingCell(cellnum, rowIndex, false); }
} else if(policy == MissingCellPolicy.RETURN_BLANK_AS_NULL) {
if(cell == null || cell.getCellTypeEnum() == CellType.BLANK) { return null; }
}
return cell;
}

/* Not supported */

/**
Expand Down Expand Up @@ -154,21 +168,6 @@ public void setRowNum(int rowNum) {
throw new NotSupportedException();
}

/**
* Not supported
*/
@Override
public Cell getCell(int cellnum, MissingCellPolicy policy) {
StreamingCell cell = (StreamingCell) cellMap.get(cellnum);
if (policy == Row.CREATE_NULL_AS_BLANK) {
if (cell == null) return new StreamingCell(cellnum, rowIndex, false);

} else if (policy == Row.RETURN_BLANK_AS_NULL) {
if (cell.getCellType() == Cell.CELL_TYPE_BLANK) return null;
}
return cell;
}

/**
* Not supported
*/
Expand Down

0 comments on commit cfb078c

Please sign in to comment.