Independentsoft
Home
Purchase
Support
Company
Contact
Word .NET
>
Tutorial
> Paragraph indentation
The following example shows you how to set paragraph indentation.
C# example
using System; using Independentsoft.Office.Word; namespace Sample { class Program { static void Main(string[] args) { WordDocument doc = new WordDocument(); // Paragraph with left indentation Run run1 = new Run(); run1.AddText("This paragraph has left indentation. The entire paragraph is indented from the left margin."); Paragraph paragraph1 = new Paragraph(); paragraph1.Add(run1); Indentation indent1 = new Indentation(); indent1.Left = 720; // 720 twips = 0.5 inch paragraph1.Indentation = indent1; // Paragraph with first line indentation Run run2 = new Run(); run2.AddText("This paragraph has first line indentation. Only the first line is indented, which is common for book paragraphs."); Paragraph paragraph2 = new Paragraph(); paragraph2.Add(run2); Indentation indent2 = new Indentation(); indent2.FirstLine = 720; // 720 twips = 0.5 inch paragraph2.Indentation = indent2; // Paragraph with hanging indentation Run run3 = new Run(); run3.AddText("This paragraph has hanging indentation. The first line starts at the margin but subsequent lines are indented. This is often used for bibliographies."); Paragraph paragraph3 = new Paragraph(); paragraph3.Add(run3); Indentation indent3 = new Indentation(); indent3.Left = 720; indent3.Hanging = 720; // Creates hanging effect paragraph3.Indentation = indent3; // Paragraph with both left and right indentation Run run4 = new Run(); run4.AddText("This paragraph has both left and right indentation. It appears as a block quote, indented from both margins."); Paragraph paragraph4 = new Paragraph(); paragraph4.Add(run4); Indentation indent4 = new Indentation(); indent4.Left = 720; indent4.Right = 720; paragraph4.Indentation = indent4; doc.Body.Add(paragraph1); doc.Body.Add(paragraph2); doc.Body.Add(paragraph3); doc.Body.Add(paragraph4); doc.Save("c:\\test\\output.docx", true); } } }
VB example
Imports System Imports Independentsoft.Office.Word Module Module1 Sub Main(ByVal args() As String) Dim doc As WordDocument = New WordDocument() ' Paragraph with left indentation Dim run1 As Run = New Run() run1.AddText("This paragraph has left indentation. The entire paragraph is indented from the left margin.") Dim paragraph1 As Paragraph = New Paragraph() paragraph1.Add(run1) Dim indent1 As Indentation = New Indentation() indent1.Left = 720 ' 720 twips = 0.5 inch paragraph1.Indentation = indent1 ' Paragraph with first line indentation Dim run2 As Run = New Run() run2.AddText("This paragraph has first line indentation. Only the first line is indented, which is common for book paragraphs.") Dim paragraph2 As Paragraph = New Paragraph() paragraph2.Add(run2) Dim indent2 As Indentation = New Indentation() indent2.FirstLine = 720 ' 720 twips = 0.5 inch paragraph2.Indentation = indent2 ' Paragraph with hanging indentation Dim run3 As Run = New Run() run3.AddText("This paragraph has hanging indentation. The first line starts at the margin but subsequent lines are indented. This is often used for bibliographies.") Dim paragraph3 As Paragraph = New Paragraph() paragraph3.Add(run3) Dim indent3 As Indentation = New Indentation() indent3.Left = 720 indent3.Hanging = 720 ' Creates hanging effect paragraph3.Indentation = indent3 ' Paragraph with both left and right indentation Dim run4 As Run = New Run() run4.AddText("This paragraph has both left and right indentation. It appears as a block quote, indented from both margins.") Dim paragraph4 As Paragraph = New Paragraph() paragraph4.Add(run4) Dim indent4 As Indentation = New Indentation() indent4.Left = 720 indent4.Right = 720 paragraph4.Indentation = indent4 doc.Body.Add(paragraph1) doc.Body.Add(paragraph2) doc.Body.Add(paragraph3) doc.Body.Add(paragraph4) doc.Save("c:\test\output.docx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*