officefileapi-116857-word-processing-document-api-examples-layout-how-to-add-line-numbering.md
The following example illustrates how to adjust line numbering to the specified document section.
To enable Line Numbering , set the RichEditView.AllowDisplayLineNumbers option for the current view to true and specify the SectionLineNumbering.CountBy property to a non-zero positive value.
In SimpleView and DraftView views line numbers are outside the default visible area, so you have to provide a space to display them by setting the left padding to a higher value (use the SimpleView.Padding or the DraftView.Padding property, respectively).
The line numbering font face and font color are specified by the Line Number character style.
To specify line numbering, the following properties are provided:
All the line numbering parameters can be accessed through the Section.LineNumbering property.
View Example: Word Processing Document API – How to Process Word Documents in Code
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit;
using DevExpress.Office;
static void LineNumbering(RichEditDocumentServer wordProcessor) {
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.Docx);
// Access a document.
Document document = wordProcessor.Document;
// Specify the document’s measure units.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Access the first document section.
Section sec = document.Sections[0];
// Specify line numbering parameters for the section.
sec.LineNumbering.CountBy = 2;
sec.LineNumbering.Start = 1;
sec.LineNumbering.Distance = 0.25f;
sec.LineNumbering.RestartType = LineNumberingRestart.NewSection;
}
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.XtraRichEdit
Imports DevExpress.Office
Private Shared Sub LineNumbering(ByVal wordProcessor As RichEditDocumentServer)
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.Docx)
' Access a document.
Dim document As Document = wordProcessor.Document
' Specify the document’s measure units.
document.Unit = DocumentUnit.Inch
' Access the first document section.
Dim sec As Section = document.Sections(0)
' Specify line numbering parameters for the section.
sec.LineNumbering.CountBy = 2
sec.LineNumbering.Start = 1
sec.LineNumbering.Distance = 0.25F
sec.LineNumbering.RestartType = LineNumberingRestart.NewSection
End Sub