From 019279269bdd9db5f9724531a650a40456f4be2b Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Sat, 19 Dec 2009 11:27:01 +0000 Subject: [PATCH] fixed CellRangeUtil.mergeCellRanges to work for adjacent cell regions 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 | 6 ++++-- .../org/apache/poi/hssf/record/cf/TestCellRange.java | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/cf/CellRangeUtil.java b/src/java/org/apache/poi/hssf/record/cf/CellRangeUtil.java index 5769e88c3e..b795d02288 100644 --- a/src/java/org/apache/poi/hssf/record/cf/CellRangeUtil.java +++ b/src/java/org/apache/poi/hssf/record/cf/CellRangeUtil.java @@ -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 lst = new ArrayList(); + for(CellRangeAddress cr : cellRanges) lst.add(cr); + List temp = mergeCellRanges(lst); return toArray(temp); } private static List mergeCellRanges(List cellRangeList) diff --git a/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java b/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java index 7b9989e47b..ced198a5a2 100644 --- a/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java +++ b/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java @@ -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()); + } } -- 2.39.5