Forums     Knowledge Base     OfficeWriter Online     
 
 
This documentation is for
OfficeWriter v3.8.1
.NET Platform

View Docs for Another
Version or Platform

Programmer's Reference > WordApplication API > Table

The Table Object

     extends Element



Represents a table in the Word document.

To create a new table, use Element.InsertTableBefore() or InsertTableAfter(). To get an existing table, use Element.Elements or Element.Children and check which elements are of type Element.Type.Table.

The following sample demonstrates inserting a new table at the end of a document as well as finding the first table in a document.



Examples:

[csharp]
// Insert a table at the end of a new document with 3 rows and 5 columns
WordApplication app = new WordApplication();
Document doc = app.Create();
Table table = doc.InsertTableAfter(3, 5);

// Get the first table of an existing document
WordApplication app = new WordApplication();
Document doc = app.Open(@"C:\sample.doc");
Table table = doc.Elements(Element.Type.Table)[0];
[vbnet]
' Insert a table at the end of a new document with 3 rows and 5 columns
Dim app As New WordApplication()
Dim doc As Document = app.Create()
Dim table As Table = doc.InsertTableAfter(3, 5)

' Get the first table of an existing document
Dim app As New WordApplication()
Dim doc As Document = app.Open("C:\sample.doc")
Dim table As Table = doc.Elements(Element.Type.Table)(0)


Please note that this object inherits methods and properties not shown here from the following objects:

Table Properties

Property Type Access Description
AbsolutePositioning AbsolutePositioning read

Returns an AbsolutePositioning object on which you can control the absolute positioning for the table

Formatting TableFormatting read
write

Sets or returns a TableFormatting object representing the formatting of this table (borders, padding, shading, etc)

Item TableCell read

Returns an TableCell object that represents the table cell that exists at the given column and row

NumRows int read

Returns an int representing the number of rows in the first row of this table

PreferredColumnWidth int read
write

Returns or sets an int representing the width of a particular column

PreferredColumnWidthUnits TableCell.WidthUnits read
write

Sets or returns a TableCell.WidthUnits object that represents the units used for the width of a particular column

PreferredWidth int read
write

Returns or sets an int that represents the preferred width of this table in twips

RowHeight int read
write

Returns or sets an int representing the height of a particular row in the table

RowHeightExact boolean read
write

Returns or sets a boolean that represents if the row height is "exact" (true) or "at least" (false)

Style NamedStyle read
write

Sets or returns a NamedStyle object that represents the Style of the current table



Table Methods

ReturnsSignature and Description
void AddColumns ( int numColumns )
Adds a specified number of columns to the horizontal end of the table
void AddRows ( int numRows )
Adds a specified number of rows to the vertical end of the table
void CreateBookmarkOnRow ( int row , String name )

Creates a bookmark on the specified row using the specified name

void DeleteColumns ( int startIndex , int numColumns )
Deletes one or more columns from the table.
void DeleteRows ( int startIndex , int numRows )
Deletes one or more rows from the table.
int GetNumColumns ( int row )
Returns the number of columns in the specified row of the table
void ImportData ( Object[] row )
Imports data from an array of objects to the current table.
void InsertColumns ( int index , int numColumns )
Inserts one or more columns at the specified position in the table.
void InsertRows ( int index , int numRows )
Inserts one or more rows at the specified position in the table.
void MergeCells ( int firstRow , int firstCol , int numRows , int numCols )
Merges the specified set of cells into a single cell.



Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.