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

Creating Lists

Lists

To add a list to a section= of your document, use one of the following methods. All of the methods ins= ert a list at a specified point in an Element. An Element object represents= an editable region in a document, such as a section or a table cell. The d= ocument itself is an Element (the Document class extends Element). Later, w= e will add a list to a Document object.

Before adding a list to your file, you must create a content region in w= hich to insert the list. Each editable region in a Word file is represented= by an Element object, or an object that extends Element, such as a Documen= t object.

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

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

=20
//--- The boolean parameter specifies whether the
//--- list is numbered (true) or bulleted (false).
List numberedList =3D doc.InsertListAfter(true);
=20

Next, create list entries. To add a new entry, call either List.AddEntry= or List.InsertEntry.

=20
//--- AddEntry's parameter specifies the 0-based
//--- indent level at which to insert the new entry. A list
//--- may contain up to 9 levels, so the deepest level
//--- is 8.  The following inserts the first list entry, at
//--- the top list level.
ListEntry firstListEntry =3D numberedList.AddEntry(0);

//--- InsertEntry's first parameter specifies the 0-based
//--- position in the list at which to insert the new entry
//--- (for the first entry this parameter should be O,
//--- for the second 1, and so on).  The second parameter
//--- specifies the 0-based level of the new entry.  A list
//--- may contain up to 9 levels, so the deepest level
//--- is 8.  The following inserts the second list entry, at
//--- the top list level.
ListEntry secondListEntry =3D numberedList.InsertEntry(1, 0);
=20

To add text to a list entry call one of the Element class's InsertTextAf= ter or InsertTextBefore methods. You can apply a font to the text by passing a Font = object to InsertTextAfter or InsertTextBefore. The following lines create a= Font object that we will use later when adding text to the paragraph:

=20
Font listFont =3D doc.CreateFont();
listFont.FontName =3D "Times New Roman";
listFont.FontSize =3D 10;
=20

The method InsertTextAfter takes a string and inserts it at the end of t= he list entry. The method's second parameter specifies a Font object (creat= ed above) to apply to the text.

=20
firstListEntry.InsertTextAfter("OfficeWriter for Word"=
,
     listFont);
secondListEntry.InsertTextAfter("OfficeWriter for Excel",
     listFont);
=20

You can access existing lists 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");
List firstList =3D doc.GetElements(Element.Type.List)[0];
=20

See Also

List

ListEntry

ListLevel

------=_Part_8544_419312350.1711649512740--