C#/VB.NET: Apply Emphasis Marks in Word

The emphasis mark is used in Word documents to emphasize words and make them more noticeable. It is usually a dot or a circle placed above or under the emphasized words. However, manually selecting words and applying emphasis marks on them takes a lot of work. Fortunately, Spire.Doc for .NET provides a much easier way to apply emphasis marks by codes. This article will show you how to apply emphasis marks to text in Word documents using Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Apply Emphasis Mark to Specified Text

The detailed steps are as follows:

  • Create a Document instance.
  • Load the Word document from disk using Document.LoadFromFile() method.
  • Find the text you need to emphasize using Document.FindAllString() method.
  • Apply emphasis mark to the found text through CharacterFormat.EmphasisMark property.
  • Save the document to another Word file using Document.SaveToFile() method.
  • C#
  • VB.NET
using System;
using Spire.Doc;
using Spire.Doc.Documents;

namespace applyemphasismark
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document instance
            Document document = new Document();

            //Load the Word document from disk
            document.LoadFromFile(@"D:\testp\test.docx");

            //Find text you want to emphasize
            TextSelection[] textSelections = document.FindAllString("Spire.Doc for .NET", false, true);

            //Apply emphasis mark to the found text
            foreach (TextSelection selection in textSelections)
            {
                selection.GetAsOneRange().CharacterFormat.EmphasisMark = Emphasis.Dot;
            }

            //Save the document to another Word file
            string output = "ApllyEmphasisMark.docx";
            document.SaveToFile(output, FileFormat.Docx);
        }
    }
}

C#/VB.NET: Apply Emphasis Marks in Word

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.