Committing RemoveMerged fix to the release branch.

PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353165 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Danny Muid 2003-06-27 22:05:20 +00:00
parent 9c9b3a6094
commit 97cdd24242
2 changed files with 38 additions and 9 deletions

View File

@ -469,11 +469,12 @@ public class Sheet implements Model
numMergedRegions--; numMergedRegions--;
if (rec.getNumAreas() == 0) if (rec.getNumAreas() == 0)
{ {
mergedRecords.remove(pos);
if (merged == rec) if (merged == rec)
merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1); merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1);
int removePos = ((Integer) mergedLocs.get(pos)).intValue(); int removePos = ((Integer) mergedLocs.get(pos)).intValue();
records.remove(removePos); records.remove(removePos);
mergedRecords.remove(pos);
mergedLocs.remove(pos); mergedLocs.remove(pos);
} }
} }

View File

@ -54,18 +54,20 @@
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.record.HCenterRecord;
import org.apache.poi.hssf.record.VCenterRecord;
import org.apache.poi.hssf.record.WSBoolRecord;
import org.apache.poi.hssf.record.SCLRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import junit.framework.TestCase;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.record.HCenterRecord;
import org.apache.poi.hssf.record.SCLRecord;
import org.apache.poi.hssf.record.VCenterRecord;
import org.apache.poi.hssf.record.WSBoolRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.util.Region;
/** /**
* Tests HSSFSheet. This test case is very incomplete at the moment. * Tests HSSFSheet. This test case is very incomplete at the moment.
* *
@ -254,4 +256,30 @@ public class TestHSSFSheet
assertTrue(sclLoc == window2Loc + 1); assertTrue(sclLoc == window2Loc + 1);
} }
/**
* When removing one merged region, it would break
*
*/
public void testRemoveMerged() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
Region region = new Region(0, (short)0, 1, (short)1);
sheet.addMergedRegion(region);
region = new Region(1, (short)0, 2, (short)1);
sheet.addMergedRegion(region);
sheet.removeMergedRegion(0);
region = sheet.getMergedRegionAt(0);
assertEquals("Left over region should be starting at row 1", 1, region.getRowFrom());
sheet.removeMergedRegion(0);
}
public static void main(java.lang.String[] args) {
junit.textui.TestRunner.run(TestHSSFSheet.class);
}
} }