You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2012/02/07 10:21:15 UTC

svn commit: r1241387 - in /poi/trunk/src: documentation/content/xdocs/status.xml ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java

Author: yegor
Date: Tue Feb  7 09:21:15 2012
New Revision: 1241387

URL: http://svn.apache.org/viewvc?rev=1241387&view=rev
Log:
Bugzilla 525612: added  methods to get/set a table row's Can't Split and Repeat Header attributes in XWPF

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1241387&r1=1241386&r2=1241387&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Feb  7 09:21:15 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="add">52562 - Added methods to get/set a table row's Can't Split and Repeat Header attributes  in XWPF</action>
            <action dev="poi-developers" type="add">52561 - Added methods to set table inside borders and cell margins in XWPF</action>
            <action dev="poi-developers" type="add">52569 - Support DConRefRecord in HSSF</action>
            <action dev="poi-developers" type="add">52575 - added an option to ignore missing workbook references in formula evaluator</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java?rev=1241387&r1=1241386&r2=1241387&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java Tue Feb  7 09:21:15 2012
@@ -22,13 +22,16 @@ import java.util.List;
 
 import org.apache.poi.util.Internal;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTrPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
 
 
 /**
  * @author gisellabronzetti
+ * @author gregg morris - added removeCell(), setCantSplitRow(), setRepeatHeader()
  */
 public class XWPFTableRow {
 
@@ -64,6 +67,11 @@ public class XWPFTableRow {
         return null;
     }
     
+    public void removeCell(int pos) {
+        if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
+        	tableCells.remove(pos);
+        }    	
+    }
     /**
      * adds a new TableCell at the end of this tableRow
      */
@@ -105,7 +113,6 @@ public class XWPFTableRow {
         return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
     }
 
-
     private CTTrPr getTrPr() {
         return (ctRow.isSetTrPr()) ? ctRow.getTrPr() : ctRow.addNewTrPr();
     }
@@ -136,9 +143,67 @@ public class XWPFTableRow {
 	 */
 	public XWPFTableCell getTableCell(CTTc cell) {
 		for(int i=0; i<tableCells.size(); i++){
-			if(tableCells.get(i).getCTTc() == cell) return tableCells.get(i); 
+			if (tableCells.get(i).getCTTc() == cell)
+				return tableCells.get(i); 
 		}
 		return null;
 	}
 
+	/**
+	 * This attribute controls whether to allow table rows to split across pages.
+	 * The logic for this attribute is a little unusual: a true value means
+	 * DON'T allow rows to split, false means allow rows to split.
+	 * @param split - if true, don't allow rows to be split. If false, allow
+	 *        rows to be split.
+	 */
+	public void setCantSplitRow(boolean split) {
+		CTTrPr trpr = getTrPr();
+		CTOnOff onoff = trpr.addNewCantSplit();
+		onoff.setVal(split ? STOnOff.ON : STOnOff.OFF);
+	}
+
+	/**
+	 * Return true if the "can't split row" value is true. The logic for this
+	 * attribute is a little unusual: a TRUE value means DON'T allow rows to
+	 * split, FALSE means allow rows to split.
+	 * @return true if rows can't be split, false otherwise.
+	 */
+	public boolean isCantSplitRow() {
+		boolean isCant = false;
+		CTTrPr trpr = getTrPr();
+		if (trpr.sizeOfCantSplitArray() > 0) {
+			CTOnOff onoff = trpr.getCantSplitList().get(0);
+			isCant = onoff.getVal().equals(STOnOff.ON);
+		}
+		return isCant;
+	}
+
+	/**
+	 * This attribute controls whether to repeat a table's header row at the top
+	 * of a table split across pages.
+	 * @param repeat - if TRUE, repeat header row at the top of each page of table;
+	 *                 if FALSE, don't repeat header row.
+	 */
+	public void setRepeatHeader(boolean repeat) {
+		CTTrPr trpr = getTrPr();
+		CTOnOff onoff = trpr.addNewTblHeader();
+		onoff.setVal(repeat ? STOnOff.ON : STOnOff.OFF);
+	}
+
+	/**
+	 * Return true if a table's header row should be repeated at the top of a
+	 * table split across pages.
+	 * @return true if table's header row should be repeated at the top of each
+	 *         page of table, false otherwise.
+	 */
+	public boolean isRepeatHeader() {
+		boolean repeat = false;
+		CTTrPr trpr = getTrPr();
+		if (trpr.sizeOfTblHeaderArray() > 0) {
+			CTOnOff rpt = trpr.getTblHeaderList().get(0);
+			repeat = rpt.getVal().equals(STOnOff.ON);
+		}
+		return repeat;
+	}
+
 }// end class

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java?rev=1241387&r1=1241386&r2=1241387&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java Tue Feb  7 09:21:15 2012
@@ -20,27 +20,50 @@ package org.apache.poi.xwpf.usermodel;
 import junit.framework.TestCase;
 
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
 
 public class TestXWPFTableRow extends TestCase {
 
-	
-	
 	@Override
 	protected void setUp() throws Exception {
-		// TODO Auto-generated method stub
 		super.setUp();
 	}
 
-	public void testSomething() throws Exception {
-		
+	public void testCreateRow() throws Exception {
 		CTRow ctRow = CTRow.Factory.newInstance();
-
+		assertNotNull(ctRow);
 	}
 	
 	@Override
 	protected void tearDown() throws Exception {
-		// TODO Auto-generated method stub
 		super.tearDown();
 	}
 
+	public void testSetGetCantSplitRow() {
+            // create a table
+            XWPFDocument doc = new XWPFDocument();
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // table has a single row by default; grab it
+            XWPFTableRow tr = table.getRow(0);
+            assertNotNull(tr);
+
+            tr.setCantSplitRow(true);
+            boolean isCant = tr.isCantSplitRow();
+            assert(isCant);
+	}
+
+	public void testSetGetRepeatHeader() {
+        // create a table
+            XWPFDocument doc = new XWPFDocument();
+            CTTbl ctTable = CTTbl.Factory.newInstance();
+            XWPFTable table = new XWPFTable(ctTable, doc);
+            // table has a single row by default; grab it
+            XWPFTableRow tr = table.getRow(0);
+            assertNotNull(tr);
+
+            tr.setRepeatHeader(true);
+            boolean isRpt = tr.isRepeatHeader();
+            assert(isRpt);
+	}
 }



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