diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 04a91b624..df8cbf2d2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -37,6 +37,7 @@ import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.FormulaError; import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.ss.usermodel.RichTextString; +import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import org.apache.poi.util.Internal; @@ -107,7 +108,7 @@ public final class XSSFCell implements Cell { } else { int prevNum = row.getLastCellNum(); if(prevNum != -1){ - _cellNum = row.getCell(prevNum-1).getColumnIndex() + 1; + _cellNum = row.getCell(prevNum-1, Row.RETURN_NULL_AND_BLANK).getColumnIndex() + 1; } } _sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java index 4dcaf63bf..e48f7705e 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java @@ -407,4 +407,40 @@ public final class TestXSSFCell extends BaseTestCell { XSSFTestDataSamples.writeOutAndReadBack(wb); } + + public void testBug56644ReturnNull() throws IOException { + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56644.xlsx"); + try { + wb.setMissingCellPolicy(Row.RETURN_BLANK_AS_NULL); + Sheet sheet = wb.getSheet("samplelist"); + Row row = sheet.getRow(20); + row.createCell(2); + } finally { + wb.close(); + } + } + + public void testBug56644ReturnBlank() throws IOException { + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56644.xlsx"); + try { + wb.setMissingCellPolicy(Row.RETURN_NULL_AND_BLANK); + Sheet sheet = wb.getSheet("samplelist"); + Row row = sheet.getRow(20); + row.createCell(2); + } finally { + wb.close(); + } + } + + public void testBug56644CreateBlank() throws IOException { + Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56644.xlsx"); + try { + wb.setMissingCellPolicy(Row.CREATE_NULL_AS_BLANK); + Sheet sheet = wb.getSheet("samplelist"); + Row row = sheet.getRow(20); + row.createCell(2); + } finally { + wb.close(); + } + } } diff --git a/test-data/spreadsheet/56644.xlsx b/test-data/spreadsheet/56644.xlsx new file mode 100644 index 000000000..f82be1792 Binary files /dev/null and b/test-data/spreadsheet/56644.xlsx differ