]> source.dussan.org Git - poi.git/commitdiff
fixed CellRangeUtil.mergeCellRanges to work for adjacent cell regions
authorYegor Kozlov <yegor@apache.org>
Sat, 19 Dec 2009 11:27:01 +0000 (11:27 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 19 Dec 2009 11:27:01 +0000 (11:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@892462 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/cf/CellRangeUtil.java
src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java

index 5769e88c3eb5925a2cc00404b1bde3a196440652..b795d0228840b8b50e8c62430e797df7a6aa08cf 100644 (file)
@@ -18,7 +18,6 @@
 package org.apache.poi.hssf.record.cf;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.apache.poi.ss.util.CellRangeAddress;
@@ -96,7 +95,10 @@ public final class CellRangeUtil
                if(cellRanges.length < 1) {
                        return cellRanges;
                }
-               List temp = mergeCellRanges(Arrays.asList(cellRanges));
+
+        List<CellRangeAddress> lst = new ArrayList<CellRangeAddress>();
+        for(CellRangeAddress cr : cellRanges) lst.add(cr);
+        List temp = mergeCellRanges(lst);
                return toArray(temp);
        }
        private static List mergeCellRanges(List cellRangeList)
index 7b9989e47bde4794b0dd48e90724e49f46b06d29..ced198a5a22dc2e58fec529e39ee23e33ffd5504 100644 (file)
@@ -184,4 +184,12 @@ public final class TestCellRange extends TestCase
                assertEquals(100, box9x9.getNumberOfCells());
                assertEquals(121, box10to20c.getNumberOfCells());
        }
+
+    public void testMergeCellRanges() {
+        CellRangeAddress cr1 = CellRangeAddress.valueOf("A1:B1");
+        CellRangeAddress cr2 = CellRangeAddress.valueOf("A2:B2");
+        CellRangeAddress[] cr3 = CellRangeUtil.mergeCellRanges(new CellRangeAddress[]{cr1, cr2});
+        assertEquals(1, cr3.length);
+        assertEquals("A1:B2", cr3[0].formatAsString());
+    }
 }