]> source.dussan.org Git - poi.git/commitdiff
Bug 56644: Fix adding cells if MissingCellPolicy is set to NULL_FOR_BLANK and the...
authorDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 11:11:34 +0000 (11:11 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 22 Dec 2014 11:11:34 +0000 (11:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647291 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
test-data/spreadsheet/56644.xlsx [new file with mode: 0644]

index 04a91b6240c34cf686d8bb8ae6c85a084fc9d5cc..df8cbf2d2c0072b1b7f8fda72f0cad0802f9b820 100644 (file)
@@ -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();
index 4dcaf63bf84c83ebaae9252b6c3aafdcdcccd2cd..e48f7705e868d7c1766e015e716241405496810f 100644 (file)
@@ -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 (file)
index 0000000..f82be17
Binary files /dev/null and b/test-data/spreadsheet/56644.xlsx differ