All the indices shift when you remove, so there will be no third merged index on the third iteration.
sheet.removeMergedRegion(0) x3 will remove all three regions.
Gabriel Chan wrote:
I've tried it with RC2 release and it's still the same kind of error. All I did was opened a blank spread sheet in excel, merged three regions, saved it, open it with POI and them tried to delete them all.
Gabriel Chan Programmer Analyst #202, 12315 Stony Plain Road Edmonton Alberta Canada T5N 3Y8 Telephone (780) 437-3020 Fax (780) 462-6984 Toll Free: 1-800-661-3306
-----Original Message----- From: Danny Mui [mailto:[EMAIL PROTECTED] Sent: Friday, January 09, 2004 11:43 AM To: POI Developers List Subject: Re: Problem Removing Merged Regions
I believe these were fixed by RC2. The clone fix should be in RC2.
Gabriel Chan wrote:
I am having 2 problems when attempting to remove merged regions:
1) If there is more than 1 merged region in a sheet, and I try to remove
all
of them, one merged region always remains:
int numRegions = sheet.getNumMergedRegions();
System.out.println("Initial number of merged regions: " + numRegions);
for (int regionNum = 0; regionNum < numRegions; regionNum++) { sheet.removeMergedRegion(regionNum); System.out.println("Removed region: "+ regionNum);
}
System.out.println("Final number of merged regions: " +
numRegions);
If I run the above code, the number of merged region remaining
is
1.
2) If I clone a sheet with merged regions and delete the merged regions in the clone them I not only get problem 1, but also exceptions:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 at java.util.ArrayList.RangeCheck(ArrayList.java:507) at java.util.ArrayList.remove(ArrayList.java:392) at
org.apache.poi.hssf.record.MergeCellsRecord.removeAreaAt(MergeCellsRecord.ja
va:188) at org.apache.poi.hssf.model.Sheet.removeMergedRegion(Sheet.java:496) at
org.apache.poi.hssf.usermodel.HSSFSheet.removeMergedRegion(HSSFSheet.java:56
4) at
org.apache.poi.hssf.usermodel.eq.HSSFUtil.removeAllRegionsFromSheet(HSSFUtil
.java:252) at
org.apache.poi.hssf.usermodel.examples.ReadWriteWorkbook.main(ReadWriteWorkb
ook.java:147) Exception in thread "main" Process terminated with exit code 1
????????? Gabriel Chan Programmer Analyst #202, 12315 Stony Plain Road Edmonton Alberta Canada T5N 3Y8 Telephone (780) 437-3020 Fax (780) 462-6984 Toll Free: 1-800-661-3306
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
