Hello (again)-
One more question. What is the best way to put a border around parts of a table. For instance, I'm trying to do the folloeing three things:
1. Put a single, border around the outside edge of a table (i.e., as if the table was sitting inside a rectangle)
2. Put a single border around a whole row in a table.
3. Put a border on one edge of a column (i.e., to create a vertical rule).
What would be the best way to do what I'm trying to do?
Regards-
Eric
Table Borders
Re: Table Borders
Support · Nov 28, 2005Hi Eric,
The best way to place borders (or lines) around (or between) Table, Rows, Columns or Cells is by creating Lines or Rectangle objects and placing them at the desired location.
1. So for placing a border around the entire table just create a Rectangle using the Table's X, Y location as well as the GetVisibleWidth and GetVisibleHeight methods (see below example).
2. To put a border around an entire row you will need to find the start X location of that row (by calculating the row heights of all the previous rows) and create a Rectangle accordingly (see below example).
3. As for putting a line between two columns to act as a vertical rule, you will just need to find the start Y location of the column you want to use, and then create the appropriate Line object (see below example).
The C# code below shows the creation of a simple table and each of the above operations are demonstrated:
Document document = new Document();
Page page = new Page();
Table table = new Table( 0, 0, 450, 450 );
table.Columns.Add( 100 );
table.Columns.Add( 100 );
table.Columns.Add( 100 );
table.Columns.Add( 100 );
Row row1 = table.Rows.Add( 100 );
row1.Cells.Add( "Cell 1" );
row1.Cells.Add( "Cell 2" );
row1.Cells.Add( "Cell 3" );
row1.Cells.Add( "Cell 4" );
Row row2 = table.Rows.Add( 100 );
row2.Cells.Add( "Cell 5" );
row2.Cells.Add( "Cell 6" );
row2.Cells.Add( "Cell 7" );
row2.Cells.Add( "Cell 8" );
Row row3 = table.Rows.Add( 100 );
row3.Cells.Add( "Cell 9" );
row3.Cells.Add( "Cell 10" );
row3.Cells.Add( "Cell 11" );
row3.Cells.Add( "Cell 12" );
Row row4 = table.Rows.Add( 100 );
row4.Cells.Add( "Cell 13" );
row4.Cells.Add( "Cell 14" );
row4.Cells.Add( "Cell 15" );
row4.Cells.Add( "Cell 16" );
// Calculate the X location of the third Row
float row3LocationX = 0;
for( int i = 0; i < 2; i++ )
{
row3LocationX += table.Rows[i].ActualRowHeight;
}
// Add the table to the page
page.Elements.Add( table );
// Add a rectangle around the entire table
page.Elements.Add( new Rectangle( table.X, table.Y, table.GetVisibleWidth(), table.GetVisibleHeight(), Color.Blue, 1 ) );
// Add a rectangle around the third row
page.Elements.Add( new Rectangle( 0, row3LocationX, table.GetVisibleWidth(), table.Rows[2].ActualRowHeight, Color.Red, 2 ) );
// Add a vertical line between column one and two
page.Elements.Add( new Line( table.Columns[0].Width, 0, table.Columns[0].Width, table.GetVisibleHeight(), 3 ) );
document.Pages.Add( page );
document.DrawToWeb( this, "Table.pdf" );
Thanks,
ceTe Software Support Team
Re: Table Borders
Forum member · Nov 28, 2005Thanks for your quick reply to this question and the one regarding superscript text.