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
Table Element.InsertTableAfter(int rows, int columns)=20
Inserts an empty table, with a specified number of rows and column= s, at the end of the element.
Table Element.InsertTableAfter(int rows, int columns, TableForma= tting props)=20
Inserts an empty table, with a specified number of rows and column= s, at the end of the element. This method applies a set of table formatting= properties (contained in a TableFormatting object) to the new table.
= li>Table Element.InsertTableBefore(int rows, int columns)=20
Inserts an empty table, with a specified number of rows and column= s, at the beginning of the element.
Table Element.InsertTableBefore(int rows, int columns, TableForm= atting props)=20
Inserts an empty table, with a specified number of rows and column= s, at the beginning of the element. This method applies a set of table form= atting properties (contained in a TableFormatting object) to the new table.=
Table Position.InsertTable(int rows, int columns)=20
Inserts an empty table at a specified position within an Element. = A Position object represents a cursor.
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.
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:
//--- 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:= p>
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.
//--- 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.
//--- 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
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:
WordApplication wwapp =3D new WordApplication(); Document doc =3D wwapp.Create(); TableFormatting tblFormatting =3D doc.CreateTableFormatting();=20
Next, set TableFormatting properties.
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.
Table tbl =3D doc.InsertTableAfter(3, 5, tblFormatting);=20