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
*
* @return column number for the upper left hand corner
}
public Region getMergedRegionAt(int index) {
- // TODO Auto-generated method stub
- return null;
+ CTMergeCell ctMergeCell = getMergedCells().getMergeCellArray(index);
+ return new Region(ctMergeCell.getRef());
}
public int getNumMergedRegions() {
- // TODO Auto-generated method stub
- return 0;
+ return getMergedCells().sizeOfMergeCellArray();
}
public int getNumHyperlinks() {
}
private void addNewMergeCell(Region region) {
- if (ctMergeCells == null) {
- ctMergeCells = worksheet.addNewMergeCells();
- }
+ ctMergeCells = getMergedCells();
CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
ctMergeCell.setRef(region.getRegionRef());
}
+ private CTMergeCells getMergedCells() {
+ if (ctMergeCells == null) {
+ ctMergeCells = worksheet.addNewMergeCells();
+ }
+ return ctMergeCells;
+ }
+
private CTPageSetUpPr getSheetTypePageSetUpPr() {
if (getSheetTypeSheetPr().getPageSetUpPr() == null) {
getSheetTypeSheetPr().setPageSetUpPr(CTPageSetUpPr.Factory.newInstance());
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
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.usermodel.helpers.ColumnHelper;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
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) {
XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);
assertFalse(region.contains(9, (short) 10));\r
}\r
\r
+ public void testConstructors() {\r
+ Region region_1 = new Region("A1:E7");\r
+ assertEquals(0, region_1.getColumnFrom());\r
+ assertEquals((short)4, region_1.getColumnTo());\r
+ }\r
+ \r
}\r