Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Page numbers
The example shows you how to add page numbers to a document.
C# example
using System; using Independentsoft.Office; using Independentsoft.Office.Word; using Independentsoft.Office.Word.Fields; using Independentsoft.Office.Word.HeaderFooter; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); Page pageNumber = new Page(); SimpleField simpleField = new SimpleField(pageNumber); Paragraph footerParagraph = new Paragraph(); footerParagraph.Add(simpleField); footerParagraph.HorizontalTextAlignment = HorizontalAlignmentType.Center; Footer footer = new Footer(); footer.Add(footerParagraph); Run run1 = new Run(); run1.AddText("Hello Word!"); Paragraph paragraph1 = new Paragraph(); paragraph1.Add(run1); doc.Body.Add(paragraph1); doc.Body.Footer = footer; doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports Independentsoft.Office.Word Imports Independentsoft.Office.Word.Fields Imports Independentsoft.Office.Word.HeaderFooter Module Module1 Sub Main(ByVal args As String()) Dim doc As WordDocument = New WordDocument Dim pageNumber As New Page() Dim simpleField As New SimpleField(pageNumber) Dim footerParagraph As New Paragraph() footerParagraph.Add(simpleField) footerParagraph.HorizontalTextAlignment = HorizontalAlignmentType.Center Dim footer As New Footer() footer.Add(footerParagraph) Dim run1 As New Run() run1.AddText("Hello Word!") Dim paragraph1 As New Paragraph() paragraph1.Add(run1) doc.Body.Add(paragraph1) doc.Body.Footer = footer doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*