How to change text case to all Capital letters in C#

We always need to set all the texts in capital letters when we operate the invoice, quotation and contract, etc. This article will demonstrates how to set all the text case in capital letters in C#. Spire.Doc offers a property of docObj.CharacterFormat to enable developers to set the text in AllCaps and IsSmallCaps.

Firstly, please view the original word document.

How to change text case to all Capital letters in C#

Here comes to the code snippet:

Step 1: Create a word document and load from file.

Document doc = new Document();
doc.LoadFromFile("sample.docx");

Step 2: Get the first paragraph and set its CharacterFormat to AllCaps.

Paragraph para1 = doc.Sections[0].Paragraphs[0];
ParagraphBase docObj = para1.ChildObjects[0] as ParagraphBase;
docObj.CharacterFormat.AllCaps = true;

Step 3: Get the third paragraph and set its CharacterFormat to IsSmallCaps.

Paragraph para2 = doc.Sections[0].Paragraphs[2];
ParagraphBase docObj2 = para2.ChildObjects[0] as ParagraphBase;
docObj2.CharacterFormat.IsSmallCaps= true;

Step 4: Save the document to file.

doc.SaveToFile( "result.docx",FileFormat.Docx2013);

Effective screenshot:

How to change text case to all Capital letters in C#

Full codes:

static void Main(string[] args)
{
    Document doc = new Document();
    doc.LoadFromFile("sample.docx");

    Paragraph para1 = doc.Sections[0].Paragraphs[0];
    ParagraphBase docObj = para1.ChildObjects[0] as ParagraphBase;
    docObj.CharacterFormat.AllCaps = true;

    Paragraph para2 = doc.Sections[0].Paragraphs[2];
    ParagraphBase docObj2 = para2.ChildObjects[0] as ParagraphBase;
    docObj2.CharacterFormat.IsSmallCaps= true;

    doc.SaveToFile( "result.docx",FileFormat.Docx2013);     
}