poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1858022 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/usermodel/XSSFSheet.java testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
Date Tue, 23 Apr 2019 20:27:54 GMT
Author: centic
Date: Tue Apr 23 20:27:53 2019
New Revision: 1858022

URL: http://svn.apache.org/viewvc?rev=1858022&view=rev
Log:
Bug 63371: addMergedRegion does not update CTMergeCells.getCount

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1858022&r1=1858021&r2=1858022&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Tue Apr 23 20:27:53
2019
@@ -416,7 +416,12 @@ public class XSSFSheet extends POIXMLDoc
         CTMergeCells ctMergeCells = worksheet.isSetMergeCells() ? worksheet.getMergeCells()
: worksheet.addNewMergeCells();
         CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
         ctMergeCell.setRef(region.formatAsString());
-        return ctMergeCells.sizeOfMergeCellArray()-1;
+        final int numMergeRegions=ctMergeCells.sizeOfMergeCellArray();
+
+        // also adjust the number of merged regions overall
+        ctMergeCells.setCount(numMergeRegions);
+
+        return numMergeRegions-1;
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1858022&r1=1858021&r2=1858022&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Tue Apr
23 20:27:53 2019
@@ -131,6 +131,8 @@ import org.openxmlformats.schemas.spread
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl;
 import org.xml.sax.InputSource;
@@ -3431,4 +3433,33 @@ public final class TestXSSFBugs extends
         assertEquals("The data in the text-file should exactly match the data that we read
from the workbook", testData, value);
     }
 
+
+    @Test
+    public void bug63371() {
+        XSSFWorkbook wb = new XSSFWorkbook();
+        XSSFSheet sheet = wb.createSheet();
+
+        CellRangeAddress region = new CellRangeAddress(1, 1, 1, 2);
+        assertEquals(0, sheet.addMergedRegion(region));
+        //System.out.println(String.format("%s: index=%d", "testAddMergedRegion", index));
+
+        final List<CellRangeAddress> ranges = sheet.getMergedRegions();
+        final int numMergedRegions = sheet.getNumMergedRegions();
+        final CTWorksheet ctSheet = sheet.getCTWorksheet();
+        final CTMergeCells ctMergeCells = ctSheet.getMergeCells();
+        final List<CTMergeCell> ctMergeCellList = ctMergeCells.getMergeCellList();
+        final long ctMergeCellCount = ctMergeCells.getCount();
+        final int ctMergeCellListSize = ctMergeCellList.size();
+
+        /*System.out.println(String.format("\ntestMergeRegions(%s)", "After adding first
region"));
+        System.out.println(String.format("ranges.size=%d", ranges.size()));
+        System.out.println(String.format("numMergedRegions=%d", numMergedRegions));
+        System.out.println(String.format("ctMergeCellCount=%d", ctMergeCellCount));
+        System.out.println(String.format("ctMergeCellListSize=%d", ctMergeCellListSize));*/
+
+        assertEquals(1, ranges.size());
+        assertEquals(1, numMergedRegions);
+        assertEquals(1, ctMergeCellCount);
+        assertEquals(1, ctMergeCellListSize);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message