Microsoft Office Tutorials and References
In Depth Information
Creating a table in a Word 2007 document
The following screenshot results after adding and executing the preceding code:
Creating a table in a Word 2007 document
Using the Table object we can programmatically create a table in Word. By using
the Range object, you can set the range for the table to be drawn in Word 2007. We
have a wide selection of options for setting the style property of the table that we
are creating. In the following code sample, we are going to create a table with four
columns and three rows:
// Object instance
// System.Type.Missing;Represents a missing value in the Type
information. This field is read-only.
object pktMissing = System.Type.Missing;
// Range on the application selection
Word.Range PacktRangePresent = this.Application.Selection.Range;
// Using Table object add in the Word document
Word.Table PacktTable = this.Application.ActiveDocument.Tables.
Add(PacktRangePresent, 3, 4, ref pktMissing, ref pktMissing);
// Border propety of the Table we are creating
Word.Border[] PacktBorder = new Word.Border[6];
PacktBorder[0] = PacktTable.Borders[Word.WdBorderType.
wdBorderLeft];
PacktBorder[1] = PacktTable.Borders[Word.WdBorderType.
wdBorderRight];
 
Search JabSto ::




Custom Search