diff --git a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java index 62bbafbfa..0d0b2684d 100644 --- a/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java +++ b/src/java/org/apache/poi/hssf/record/MergeCellsRecord.java @@ -56,6 +56,7 @@ package org.apache.poi.hssf.record; import java.util.ArrayList; +import java.util.Iterator; import org.apache.poi.util.LittleEndian; @@ -327,7 +328,12 @@ public class MergeCellsRecord MergeCellsRecord rec = new MergeCellsRecord(); rec.field_1_num_areas = field_1_num_areas; rec.field_2_regions = new ArrayList(); - rec.field_2_regions.addAll(field_2_regions); + Iterator iterator = field_2_regions.iterator(); + while (iterator.hasNext()) { + MergedRegion oldRegion = (MergedRegion)iterator.next(); + rec.addArea(oldRegion.row_from, oldRegion.col_from, oldRegion.row_to, oldRegion.col_to); + } + return rec; } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java index 2b1a7c6b9..54c87a567 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestMergeCellsRecord.java @@ -55,6 +55,8 @@ package org.apache.poi.hssf.record; import junit.framework.TestCase; +import org.apache.poi.hssf.record.MergeCellsRecord.MergedRegion; + /** * Make sure the merge cells record behaves * @author Danny Mui (dmui at apache dot org) @@ -72,6 +74,15 @@ public class TestMergeCellsRecord extends TestCase { MergeCellsRecord clone = (MergeCellsRecord)merge.clone(); assertNotSame("Merged and cloned objects are the same", merge, clone); + + MergedRegion mergeRegion = merge.getAreaAt(0); + MergedRegion cloneRegion = clone.getAreaAt(0); + assertNotSame("Should not point to same objects when cloning", mergeRegion, cloneRegion); + assertEquals("New Clone Row From doesnt match", mergeRegion.row_from, cloneRegion.row_from); + assertEquals("New Clone Row To doesnt match", mergeRegion.row_to, cloneRegion.row_to); + assertEquals("New Clone Col From doesnt match", mergeRegion.col_from, cloneRegion.col_from); + assertEquals("New Clone Col To doesnt match", mergeRegion.col_to, cloneRegion.col_to); + merge.removeAreaAt(0); assertNotNull("Clone's item not removed", clone.getAreaAt(0)); }