XSSFSheet getNumMergedRegions, getMergedRegionAt methods + tests
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@645666 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b80094b1a2
commit
6e35b1d786
@ -62,6 +62,15 @@ public class Region
|
|||||||
this(region.row_from, region.col_from, region.row_to, region.col_to);
|
this(region.row_from, region.col_from, region.row_to, region.col_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Region(String ref) {
|
||||||
|
CellReference cellReferenceFrom = new CellReference(ref.substring(0, ref.indexOf(":")));
|
||||||
|
CellReference cellReferenceTo = new CellReference(ref.substring(ref.indexOf(":") + 1));
|
||||||
|
this.rowFrom = cellReferenceFrom.getRow();
|
||||||
|
this.colFrom = (short) cellReferenceFrom.getCol();
|
||||||
|
this.rowTo = cellReferenceTo.getRow();
|
||||||
|
this.colTo = (short) cellReferenceTo.getCol();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the upper left hand corner column number
|
* get the upper left hand corner column number
|
||||||
*
|
*
|
||||||
|
@ -458,13 +458,12 @@ public class XSSFSheet implements Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Region getMergedRegionAt(int index) {
|
public Region getMergedRegionAt(int index) {
|
||||||
// TODO Auto-generated method stub
|
CTMergeCell ctMergeCell = getMergedCells().getMergeCellArray(index);
|
||||||
return null;
|
return new Region(ctMergeCell.getRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumMergedRegions() {
|
public int getNumMergedRegions() {
|
||||||
// TODO Auto-generated method stub
|
return getMergedCells().sizeOfMergeCellArray();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumHyperlinks() {
|
public int getNumHyperlinks() {
|
||||||
@ -990,11 +989,16 @@ public class XSSFSheet implements Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addNewMergeCell(Region region) {
|
private void addNewMergeCell(Region region) {
|
||||||
|
ctMergeCells = getMergedCells();
|
||||||
|
CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
|
||||||
|
ctMergeCell.setRef(region.getRegionRef());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CTMergeCells getMergedCells() {
|
||||||
if (ctMergeCells == null) {
|
if (ctMergeCells == null) {
|
||||||
ctMergeCells = worksheet.addNewMergeCells();
|
ctMergeCells = worksheet.addNewMergeCells();
|
||||||
}
|
}
|
||||||
CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
|
return ctMergeCells;
|
||||||
ctMergeCell.setRef(region.getRegionRef());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CTPageSetUpPr getSheetTypePageSetUpPr() {
|
private CTPageSetUpPr getSheetTypePageSetUpPr() {
|
||||||
|
@ -23,6 +23,7 @@ import org.apache.poi.ss.usermodel.Cell;
|
|||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.ss.util.Region;
|
||||||
import org.apache.poi.xssf.model.CommentsTable;
|
import org.apache.poi.xssf.model.CommentsTable;
|
||||||
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||||
@ -548,6 +549,27 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
|
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNewMergedRegionAt() {
|
||||||
|
Workbook workbook = new XSSFWorkbook();
|
||||||
|
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||||
|
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||||
|
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||||
|
Region region = new Region("B2:D4");
|
||||||
|
sheet.addMergedRegion(region);
|
||||||
|
assertEquals("B2:D4", sheet.getMergedRegionAt(0).getRegionRef());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetNumMergedRegions() {
|
||||||
|
Workbook workbook = new XSSFWorkbook();
|
||||||
|
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||||
|
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||||
|
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||||
|
assertEquals(0, sheet.getNumMergedRegions());
|
||||||
|
Region region = new Region("B2:D4");
|
||||||
|
sheet.addMergedRegion(region);
|
||||||
|
assertEquals(1, sheet.getNumMergedRegions());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
|
private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
|
||||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);
|
XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);
|
||||||
|
@ -46,4 +46,10 @@ public class TestRegion extends TestCase {
|
|||||||
assertFalse(region.contains(9, (short) 10));
|
assertFalse(region.contains(9, (short) 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testConstructors() {
|
||||||
|
Region region_1 = new Region("A1:E7");
|
||||||
|
assertEquals(0, region_1.getColumnFrom());
|
||||||
|
assertEquals((short)4, region_1.getColumnTo());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user