Message-ID: <456458457.7731.1711619420759.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_7730_1911385990.1711619420759" ------=_Part_7730_1911385990.1711619420759 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Creating Tables

Creating Tables

To add a table to a section of your document, use one of the follow= ing methods. All of the methods insert a table at a specified point in an E= lement. An Element object represents an editable region in a document, such= as a section or paragraph. The document itself is an Element.

Before adding a table to your file, you must create a content region in = which to insert the table. Each editable region in a Word file is represent= ed by an Element object, or an object that extends Element, such as a Docum= ent object.

=20
WordApplication wwapp =3D new WordApplication();
Document doc =3D wwapp.Create();
=20

To insert an empty table, use one of the methods listed at the beginning= of this section, for example:

=20
//--- Create a table with 5 rows and 4 columns
//--- and insert it at the end of the document.
Table tbl =3D doc.InsertTableAfter(5, 4);
=20

To enter text in the table, first return one or more TableCellobjects:

=20
TableCell firstCell =3D tbl[0, 0];
TableCell secondCell =3D tbl[0, 1];
=20

To add text to a table cell, call one of the Element class's InsertTextA= fter or InsertTextBefore methods.

=20
//--- When adding text to a table, you can
//--- specify a font for the text.  First, create a Font
//--- object:
Font cellFont =3D doc.CreateFont();
cellFont.FontName =3D "Times New Roman";
cellFont.FontSize =3D 10;

//--- The following method takes a string and inserts it
//--- at the end of the table cell.  The method's second
//--- parameter specifies a Font object to apply to the
//--- text.
firstCell.InsertTextAfter("OfficeWriter for Word",
=09=09=09cellFont);
secondCell.InsertTextAfter("OfficeWriter for Excel",
=09=09=09cellFont);
=20

You can access existing tables through the Element.Elements property.

=20
//--- Open an existing Word file and get the first
//--- table.
WordApplication wwapp =3D new WordApplication();
Document doc =3D wwapp.Open(@"C:\sample.doc");
Table firstTable =3D (Table)doc.GetElements(Element.Type.Table)[0];
=20

Table Formatting

To apply a font to text in a table cell, create a Font object and pass i= t to TableCell.InsertTextAfter or TableCell.InsertTextBefore, as demonstrat= ed above.

Other paragraph formatting can be applied through the Tableobject or the= TableFormatting object. To create a TableFormatting object, call Document.= CreateTableFormatting:

=20
WordApplication wwapp =3D new WordApplication();
Document doc =3D wwapp.Create();
TableFormatting tblFormatting =3D doc.CreateTableFormatting();
=20

Next, set TableFormatting properties.

=20
tblFormatting.DefaultShading.BackgroundColor =3D Color.Gray;
tblFormatting.set_DefaultPadding(TableCell.Location.Top, 720);
=20

To assign the TableFormatting object that you created to a table, pass i= t to Element.InsertTableAfter orElement.InsertTableBefore when you create a= new table.

=20
Table tbl =3D doc.InsertTableAfter(3, 5, tblFormatting);
=20
------=_Part_7730_1911385990.1711619420759--