DocX Format Text

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Formatted text can draw the reader's attention to specific parts of a document and emphasize important information. In Word, you have several options for adjusting text, including font, size, and color. You can also adjust the alignment of the text to change how it is displayed on the page.

DocX allows you to create, format, and position paragraphs as shown in the following example.

public static void Example1()
    // Create a document.
    using (var document = DocX.Create(@"D:\SimpleFormattedParagraphs.docx"))
        document.SetDefaultFont(new Xceed.Document.NET.Font("Arial"), 15d, Color.Green);
        document.PageBackground = Color.LightGray;
        document.PageBorders = new Borders(new Border(BorderStyle.Tcbs_double, BorderSize.five, 20f, Color.Blue));

        // Add a title
        document.InsertParagraph("Formatted paragraphs").FontSize(15d).SpacingAfter(50d).Alignment =;

        // Insert a Paragraph into this document.
        var p = document.InsertParagraph();

        // Append some text and add formatting.
        p.Append("This is a simple formatted red bold paragraph")
        .Font(new Xceed.Document.NET.Font("Arial"))
        .Append(" containing a blue italic text.").Font(new Xceed.Document.NET.Font("Times New Roman")).Color(Color.Blue).Italic()

        // Insert another Paragraph into this document.
        var p2 = document.InsertParagraph();

        // Append some text and add formatting.
        p2.Append("This is a formatted paragraph using spacing, line spacing, ")
        .Font(new Xceed.Document.NET.Font("Courier New"))
        .Append(" and strike through.").StrikeThrough(StrikeThrough.strike)

        // Insert another Paragraph into this document.
        var p3 = document.InsertParagraph();

        // Append some text with 2 TabStopPositions.
        p3.InsertTabStopPosition(, 216f,
        .InsertTabStopPosition(Alignment.right, 432f,
        .Append("Text with TabStopPositions on Left\tMiddle\tand Right")

        // Insert another Paragraph into this document.
        var p4 = document.InsertParagraph();
        p4.Append("This document is using an Arial green default font of size 15. It's also using a double blue page borders and light gray page background.")

        // Save this document to disk.

When you execute the above example, you will see that a table is inserted in a word document.


Got any DocX Question?