1
votes

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

1
Did you not find MSDN documentation on Microsoft Word Interop?Abhishek
No. I think I didn't figure it out how to change an Exist word document fontsuser3570328
I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not".John Saunders
thank you .. I will remember thatuser3570328

1 Answers

2
votes

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.