mirror of https://github.com/apache/poi.git
bug 59730: promote XSSFSheet#removeMergedRegions to Sheet interface
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
46b3d8eaee
commit
80eac0c70e
|
@ -19,10 +19,12 @@ package org.apache.poi.hssf.usermodel;
|
|||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.apache.poi.ddf.EscherRecord;
|
||||
import org.apache.poi.hssf.model.DrawingManager2;
|
||||
|
@ -901,11 +903,22 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
|||
*
|
||||
* @param index of the region to unmerge
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void removeMergedRegion(int index) {
|
||||
_sheet.removeMergedRegion(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a number of merged regions of cells (hence letting them free)
|
||||
*
|
||||
* @param indices A set of the regions to unmerge
|
||||
*/
|
||||
@Override
|
||||
public void removeMergedRegions(Collection<Integer> indices) {
|
||||
for (int i : (new TreeSet<Integer>(indices)).descendingSet()) {
|
||||
_sheet.removeMergedRegion(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of merged regions
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.apache.poi.ss.usermodel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -331,6 +332,13 @@ public interface Sheet extends Iterable<Row> {
|
|||
* @param index of the region to unmerge
|
||||
*/
|
||||
void removeMergedRegion(int index);
|
||||
|
||||
/**
|
||||
* Removes a number of merged regions of cells (hence letting them free)
|
||||
*
|
||||
* @param indices A set of the regions to unmerge
|
||||
*/
|
||||
void removeMergedRegions(Collection<Integer> indices);
|
||||
|
||||
/**
|
||||
* Returns the number of merged regions
|
||||
|
|
|
@ -463,6 +463,17 @@ public class SXSSFSheet implements Sheet, Cloneable
|
|||
{
|
||||
_sh.removeMergedRegion(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a merged region of cells (hence letting them free)
|
||||
*
|
||||
* @param indices of the regions to unmerge
|
||||
*/
|
||||
@Override
|
||||
public void removeMergedRegions(Collection<Integer> indices)
|
||||
{
|
||||
_sh.removeMergedRegions(indices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of merged regions
|
||||
|
|
|
@ -1867,6 +1867,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||
*
|
||||
* @param indices A set of the regions to unmerge
|
||||
*/
|
||||
@Override
|
||||
public void removeMergedRegions(Collection<Integer> indices) {
|
||||
if (!worksheet.isSetMergeCells()) return;
|
||||
|
||||
|
|
|
@ -27,10 +27,17 @@ import static org.junit.Assert.fail;
|
|||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.poi.hssf.util.PaneInformation;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
|
@ -418,6 +425,36 @@ public abstract class BaseTestSheet {
|
|||
|
||||
wb.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove multiple merged regions
|
||||
*/
|
||||
@Test
|
||||
public void removeMergedRegions() throws IOException {
|
||||
Workbook wb = _testDataProvider.createWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
|
||||
Map<Integer, CellRangeAddress> mergedRegions = new HashMap<Integer, CellRangeAddress>();
|
||||
for (int r=0; r<10; r++) {
|
||||
CellRangeAddress region = new CellRangeAddress(r, r, 0, 1);
|
||||
mergedRegions.put(r, region);
|
||||
sheet.addMergedRegion(region);
|
||||
}
|
||||
assertCollectionEquals(mergedRegions.values(), sheet.getMergedRegions());
|
||||
|
||||
Collection<Integer> removed = Arrays.asList(0, 2, 3, 6, 8);
|
||||
mergedRegions.keySet().removeAll(removed);
|
||||
sheet.removeMergedRegions(removed);
|
||||
assertCollectionEquals(mergedRegions.values(), sheet.getMergedRegions());
|
||||
|
||||
wb.close();
|
||||
}
|
||||
|
||||
private static void assertCollectionEquals(Collection<? extends Object> expected, Collection<? extends Object> actual) {
|
||||
Set<Object> e = new HashSet<Object>(expected);
|
||||
Set<Object> a = new HashSet<Object>(actual);
|
||||
assertEquals(e, a);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shiftMerged() throws IOException {
|
||||
|
|
Loading…
Reference in New Issue