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
This commit is contained in:
Yegor Kozlov 2009-12-19 11:27:01 +00:00
parent d704d13573
commit e945a10ade
2 changed files with 12 additions and 2 deletions

View 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)

View 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());
}
}