]> source.dussan.org Git - poi.git/commitdiff
Bug 61798: Fix usage of getLastCellNum(), unfortunately this is a bit misleading...
authorDominik Stadler <centic@apache.org>
Thu, 28 Dec 2017 08:45:43 +0000 (08:45 +0000)
committerDominik Stadler <centic@apache.org>
Thu, 28 Dec 2017 08:45:43 +0000 (08:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819404 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index 8f89c67d2ff0dc8d43ae284d8fa8ecfdac0bc398..6c4956dba0f73e1163afb0870e833942ba3c0d4d 100644 (file)
@@ -266,7 +266,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
     }
 
     /**
-     * Get the number of the first cell contained in this row.
+     * Get the 0-based number of the first cell contained in this row.
      *
      * @return short representing the first logical cell in the row,
      *  or -1 if the row does not contain any cells.
index c2ee5f5befc63c93a76fd0eee7cd35359130afdd..8ca7d2b1efcc47d15134630988267c70a9387ac6 100644 (file)
@@ -3492,9 +3492,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
                 // Resetting the hyperlink array seems to break some XML nodes.
                 //worksheet.getHyperlinks().setHyperlinkArray(new CTHyperlink[0]);
                 worksheet.unsetHyperlinks();
-            } else {
+            } /*else {
                 // nothing to do
-            }
+            }*/
         }
 
         int minCell=Integer.MAX_VALUE, maxCell=Integer.MIN_VALUE;
@@ -3507,7 +3507,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
                 minCell = Math.min(minCell, row.getFirstCellNum());
             }
             if(row.getLastCellNum() != -1) {
-                maxCell = Math.max(maxCell, row.getLastCellNum());
+                maxCell = Math.max(maxCell, row.getLastCellNum()-1);
             }
         }
 
index f788619ad4772b646674e11afce8d400073a9539..106dceb494350c59efa151781d91bac01e11ad34 100644 (file)
@@ -3102,6 +3102,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         Cell cell = row.createCell(1);
         cell.setCellValue("blabla");
 
+        //0 1 2 3 4 5 6 7
+        //A B C D E F G H
         row = sheet.createRow(4);
         cell = row.createCell(7);
         cell.setCellValue("blabla");
@@ -3110,7 +3112,29 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         // to avoid having to iterate all rows/cells in each add/remove of a row or cell
         wb.write(new NullOutputStream());
 
-        assertEquals("B2:I5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef());
+        assertEquals("B2:H5", ((XSSFSheet) sheet).getCTWorksheet().getDimension().getRef());
+
+        wb.close();
+    }
+
+    @Test
+    public void test61798() throws IOException {
+        Workbook wb = new XSSFWorkbook();
+        Sheet sheet = wb.createSheet("test");
+        Row row = sheet.createRow(1);
+        Cell cell = row.createCell(1);
+        cell.setCellValue("blabla");
+
+        row = sheet.createRow(4);
+        // Allowable column range for EXCEL2007 is (0..16383) or ('A'..'XDF')
+        cell = row.createCell(16383);
+        cell.setCellValue("blabla");
+
+        // we currently only populate the dimension during writing out
+        // to avoid having to iterate all rows/cells in each add/remove of a row or cell
+        wb.write(new NullOutputStream());
+
+        assertEquals("B2:XFD5", ((XSSFSheet)sheet).getCTWorksheet().getDimension().getRef());
 
         wb.close();
     }