user3570328
user3570328

Reputation: 23

Change word document body font and Footnotes font

I have MS Word document how can I change it body font to "Arial" and Footnotes font to "Times New Roman" using C# , (Interop.Word or any free library).

I Did Search a lot before posting this Question.. But find nothing.

I found this Question but it dose not really help

How to search for a specific font in a Word document with iterop

Upvotes: 1

Views: 4246

Answers (1)

Abhishek
Abhishek

Reputation: 2945

This is some sample code. I have set the font for both body text and footnote text. The code reads "test.doc" from C drive.

using System;
using Microsoft.Office.Interop.Word;

namespace Word
{
    class Program
    {
        static void Main(string[] args)
        {                
            Application wordApp = new Application();
            string filename = @"C:\test.doc";

            Document myDoc = wordApp.Documents.Open(filename);

            if (myDoc.Paragraphs.Count > 0)
            {
                foreach (Paragraph p in myDoc.Paragraphs)
                {
                    p.Range.Font.Name = "Calibri";
                    p.Range.Text = "I have changed this text I entered previously";
                }
            }

            if (myDoc.Footnotes.Count > 0)
            {
                foreach (Footnote fn in myDoc.Footnotes)
                {
                    fn.Range.Font.Name = "Arial";
                }
            }

            myDoc.Save();
            myDoc.Close();
            myDoc = null;
            wordApp.Quit();
            wordApp = null;
        }
    }
}

If you are looking for MSDN documentation on using Word Interop then this is the link.

Upvotes: 2

Related Questions