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

Creating Sections

A Section object represents a major section in a document, like a c= hapter in a book. Many documents will only contain one section. In more com= plex documents, content can be divided into multiple sections.

 

You can assign a different set of formatting settings to each section, i= ncluding:

To add a section to your document, use one of the following methods. The= methods insert a section at the beginning or end an Element. An Element ob= ject represents an editable region in a document, such as a section or a pa= ragraph. The document itself is an Element.

Before adding a section to your file, create a Document object.

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

Call Document.CreateSectionAfter or Document.CreateSectionBefore to add = a section to the document

=20
//--- Create a section at the end of the document.
Section firstSection =3D doc.CreateSectionAfter();
=20

Next, set Section properties, for example:

=20
//--- Add a footer to the section.  A header or
//--- footer can be applied to all pages in a section,
//--- the first page in a section, odd pages only, or
//--- even pages only.  The following returns a footer
//--- for all pages in the section.
Element footer =3D firstSection.GetFooter(Section.HeaderFooterType.All);
footer.InsertTextAfter("Copyright 2007 SoftArtisans Inc.", true);

//--- Set the width of a margin in twips (1/1440 in).
firstSection.LeftMargin =3D 1440;
firstSection.RightMargin =3D 1440;
=20

After creating a Section and setting Section properties, add content. Fo= r example, add a paragraph:

=20
Paragraph para =3D firstSection.InsertParagraphAfter
     (doc.Styles[NamedStyle.BuiltIn.Normal]);
para.InsertTextAfter("OfficeWriter is now fully integrated and compati=
ble
     with SQL Server Reporting Services. Business users
     can now create and publish their Reporting Services
     reports without ever leaving Excel and Word. With
     OfficeWriter, every feature of Excel and Word is
     preserved in Reporting Services.",
     true);
=20

You can access existing sections through the Document.Sections property.=

=20
//--- Open an existing Word file and get the first
//--- section.
WordApplication wwapp =3D new WordApplication();
Document doc =3D wwapp.Open(@"C:\sample.doc");
Section firstSection =3D doc.Sections[0];
=20
------=_Part_8852_167550412.1711664767091--