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

后端 未结 3 1878
忘掉有多难
忘掉有多难 2021-01-23 07:42

I use something like this:

doc.Content.Find.Font.Name = \"Times New Roman\";

but when I step through the code the Name property doesn\'t change

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 08:06

    I used this:

    Microsoft.Office.Interop.Word._Application word;
    Microsoft.Office.Interop.Word._Document doc;
    
    bool found_next = false;
    private void search_Replace1()
    {
        word = Globals.ThisAddIn.Application;
        doc = word.ActiveDocument;
        word.Selection.Find.Font.Name = "My Font";
        found_next= word.Selection.Find.Execute(Format: true);
        if (found_next)
        {
            word.Selection.Font.Name = "Arial"; 
            //word.Selection.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;  //change color to red
        }
    }
    

提交回复
热议问题