You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by se...@apache.org on 2011/08/09 07:34:46 UTC

svn commit: r1155214 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/usermodel/Range.java testcases/org/apache/poi/hwpf/usermodel/TestBugs.java

Author: sergey
Date: Tue Aug  9 05:34:46 2011
New Revision: 1155214

URL: http://svn.apache.org/viewvc?rev=1155214&view=rev
Log:
add non-deprecated method insertTableBefore to Range

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java?rev=1155214&r1=1155213&r2=1155214&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java Tue Aug  9 05:34:46 2011
@@ -563,17 +563,18 @@ public class Range { // TODO -instantiab
 		adjustFIB(-(_end - _start));
 	}
 
-	/**
-	 * Inserts a simple table into the beginning of this range. The number of
-	 * columns is determined by the TableProperties passed into this function.
-	 *
-	 * @param props
-	 *            The table properties for the table.
-	 * @param rows
-	 *            The number of rows.
-	 * @return The empty Table that is now part of the document.
-     * @deprecated Use code shall not work with {@link TableProperties}
-	 */
+    /**
+     * Inserts a simple table into the beginning of this range. The number of
+     * columns is determined by the TableProperties passed into this function.
+     * 
+     * @param props
+     *            The table properties for the table.
+     * @param rows
+     *            The number of rows.
+     * @return The empty Table that is now part of the document.
+     * @deprecated Use code shall not work with {@link TableProperties}. Use
+     *             {@link #insertTableBefore(short, int)} instead
+     */
 	@Deprecated
 	public Table insertBefore(TableProperties props, int rows) {
 		ParagraphProperties parProps = new ParagraphProperties();
@@ -603,6 +604,42 @@ public class Range { // TODO -instantiab
         return new Table( _start, _start + diff, this, 1 );
     }
 
+    /**
+     * Inserts a simple table into the beginning of this range.
+     * 
+     * @param columns
+     *            The number of columns
+     * @param rows
+     *            The number of rows.
+     * @return The empty Table that is now part of the document.
+     */
+	public Table insertTableBefore(short columns, int rows) {
+        ParagraphProperties parProps = new ParagraphProperties();
+        parProps.setFInTable(true);
+        parProps.setItap( 1 );
+
+        final int oldEnd = this._end;
+        
+        for ( int x = 0; x < rows; x++ )
+        {
+            Paragraph cell = this.insertBefore( parProps, StyleSheet.NIL_STYLE );
+            cell.insertAfter( String.valueOf( '\u0007' ) );
+            for ( int y = 1; y < columns; y++ )
+            {
+                cell = cell.insertAfter( parProps, StyleSheet.NIL_STYLE );
+                cell.insertAfter( String.valueOf( '\u0007' ) );
+            }
+            cell = cell.insertAfter( parProps, StyleSheet.NIL_STYLE,
+                    String.valueOf( '\u0007' ) );
+            cell.setTableRowEnd( new TableProperties( columns ) );
+        }
+
+        final int newEnd = this._end;
+        final int diff = newEnd - oldEnd;
+
+        return new Table( _start, _start + diff, this, 1 );
+	}
+	
 	/**
 	 * Inserts a list into the beginning of this range.
 	 *

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java?rev=1155214&r1=1155213&r2=1155214&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java Tue Aug  9 05:34:46 2011
@@ -94,8 +94,7 @@ public class TestBugs extends TestCase
         HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "empty.doc" );
 
         Range range = doc.getRange();
-        Table table = range.insertBefore(
-                new TableProperties( (short) columns ), rows );
+        Table table = range.insertTableBefore( (short) columns, rows );
         table.sanityCheck();
         range.sanityCheck();
 



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