From cfb078c78cc33cb1369a01252b2af9d2f5b5822f Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Sun, 23 Apr 2017 12:02:24 -0400 Subject: [PATCH] Fix for #85, adding null check for MissingCellPolicy --- .../monitorjbl/xlsx/impl/StreamingRow.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/monitorjbl/xlsx/impl/StreamingRow.java b/src/main/java/com/monitorjbl/xlsx/impl/StreamingRow.java index d15da527..8fe746b2 100644 --- a/src/main/java/com/monitorjbl/xlsx/impl/StreamingRow.java +++ b/src/main/java/com/monitorjbl/xlsx/impl/StreamingRow.java @@ -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 */ /** @@ -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 */