add non-deprecated method insertTableBefore to Range

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1155214 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-08-09 05:34:46 +00:00
parent 653bf768e8
commit 8b6d31c903
2 changed files with 49 additions and 13 deletions

View File

@ -572,7 +572,8 @@ public class Range { // TODO -instantiable superclass
* @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}
* @deprecated Use code shall not work with {@link TableProperties}. Use
* {@link #insertTableBefore(short, int)} instead
*/
@Deprecated
public Table insertBefore(TableProperties props, int rows) {
@ -603,6 +604,42 @@ public class Range { // TODO -instantiable superclass
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.
*

View File

@ -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();