poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r645666 - in /poi/branches/ooxml/src: java/org/apache/poi/ss/util/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/ss/util/
Date Mon, 07 Apr 2008 20:31:44 GMT
Author: paolo
Date: Mon Apr  7 13:31:43 2008
New Revision: 645666

URL: http://svn.apache.org/viewvc?rev=645666&view=rev
Log:
XSSFSheet getNumMergedRegions, getMergedRegionAt methods + tests

Modified:
    poi/branches/ooxml/src/java/org/apache/poi/ss/util/Region.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/branches/ooxml/src/testcases/org/apache/poi/ss/util/TestRegion.java

Modified: poi/branches/ooxml/src/java/org/apache/poi/ss/util/Region.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/ss/util/Region.java?rev=645666&r1=645665&r2=645666&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/ss/util/Region.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/ss/util/Region.java Mon Apr  7 13:31:43 2008
@@ -62,7 +62,16 @@
         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

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=645666&r1=645665&r2=645666&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Mon Apr
 7 13:31:43 2008
@@ -458,13 +458,12 @@
 	}
 
     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() {
@@ -990,11 +989,16 @@
 	}
 
 	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() {

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=645666&r1=645665&r2=645666&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
Mon Apr  7 13:31:43 2008
@@ -23,6 +23,7 @@
 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;
@@ -546,6 +547,27 @@
     	sheet.createSplitPane(4, 8, 12, 12, 1);
     	assertEquals((double)8, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getYSplit());
     	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());
     }
     
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/ss/util/TestRegion.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/ss/util/TestRegion.java?rev=645666&r1=645665&r2=645666&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/ss/util/TestRegion.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/ss/util/TestRegion.java Mon Apr  7 13:31:43
2008
@@ -46,4 +46,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());
+	}
+	
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message