Word indent in C#, VB.NET

  • Demo
  • C# source
  • VB.Net source

The sample demonstrates how to indent paragraph.

//Create word document
Document document = new Document();

//Create a new secition
Section section = document.AddSection();

//Create a new paragraph
Paragraph paragraph = section.AddParagraph();

//Append Text
paragraph.AppendText("Using items list to show Indent demo.");
paragraph.ApplyStyle(BuiltinStyle.Heading3);

paragraph = section.AddParagraph();
for (int i = 0; i < 10; i++)
{
    paragraph = section.AddParagraph();
    paragraph.AppendText(String.Format("Indent Demo Node{0}", i));

    
    if(i == 0)
    {
        paragraph.ListFormat.ApplyBulletStyle();
    }
    else
    {
        paragraph.ListFormat.ContinueListNumbering();
    }

    paragraph.ListFormat.CurrentListLevel.NumberPosition = -10;
}

//Save doc file.
document.SaveToFile("Sample.doc",FileFormat.Doc);

'Create word document
Dim document_Renamed As New Document()

'Create a new secition
Dim section_Renamed As Section = document_Renamed.AddSection()

'Create a new paragraph
Dim paragraph_Renamed As Paragraph = section_Renamed.AddParagraph()

      'Append Text
      paragraph_Renamed.AppendText("Using items list to show Indent demo.")

      paragraph_Renamed.ApplyStyle(BuiltinStyle.Heading3)

      paragraph_Renamed = section_Renamed.AddParagraph()
      For i As Integer = 0 To 9
          paragraph_Renamed = section_Renamed.AddParagraph()
          Dim text As String _
              = "Indent Demo Node" & i.ToString()
          Dim txtRange As TextRange = paragraph_Renamed.AppendText(text)


          If i = 0 Then
              paragraph_Renamed.ListFormat.ApplyBulletStyle()
          Else
              paragraph_Renamed.ListFormat.ContinueListNumbering()

          End If

          paragraph_Renamed.ListFormat.CurrentListLevel.NumberPosition = -10

      Next i

'Save doc file.
document_Renamed.SaveToFile("Sample.doc",FileFormat.Doc)