Independentsoft
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Section break
The following example shows you how to insert section breaks.
C# example
using System; using Independentsoft.Office.Word; using Independentsoft.Office.Word.Sections; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); // First section content Run run1 = new Run(); run1.AddText("This is the first section. It has default page orientation."); Paragraph paragraph1 = new Paragraph(); paragraph1.Add(run1); // Add section break (next page) Section section1 = new Section(); section1.Type = SectionType.NextPage; paragraph1.Section = section1; // Second section content Run run2 = new Run(); run2.AddText("This is the second section. It starts on a new page."); Paragraph paragraph2 = new Paragraph(); paragraph2.Add(run2); // Add continuous section break Section section2 = new Section(); section2.Type = SectionType.Continuous; paragraph2.Section = section2; // Third section content Run run3 = new Run(); run3.AddText("This is the third section. It continues on the same page."); Paragraph paragraph3 = new Paragraph(); paragraph3.Add(run3); doc.Body.Add(paragraph1); doc.Body.Add(paragraph2); doc.Body.Add(paragraph3); doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports Independentsoft.Office.Word Imports Independentsoft.Office.Word.Sections Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument() ' First section content Dim run1 As Run = New Run() run1.AddText("This is the first section. It has default page orientation.") Dim paragraph1 As Paragraph = New Paragraph() paragraph1.Add(run1) ' Add section break (next page) Dim section1 As Section = New Section() section1.Type = SectionType.NextPage paragraph1.Section = section1 ' Second section content Dim run2 As Run = New Run() run2.AddText("This is the second section. It starts on a new page.") Dim paragraph2 As Paragraph = New Paragraph() paragraph2.Add(run2) ' Add continuous section break Dim section2 As Section = New Section() section2.Type = SectionType.Continuous paragraph2.Section = section2 ' Third section content Dim run3 As Run = New Run() run3.AddText("This is the third section. It continues on the same page.") Dim paragraph3 As Paragraph = New Paragraph() paragraph3.Add(run3) doc.Body.Add(paragraph1) doc.Body.Add(paragraph2) doc.Body.Add(paragraph3) doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*