Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to search a specific word in my Word file, and change it's font style. But no idea how to do it, can anyone help...
Posted

Check this, here font color is changed, you can change font style accordingly:
C# search and replace font color in Word[^]

Also get some idea from it:
Bolding Text in Microsoft Word using .NET[^]
 
Share this answer
 
v2
C#
Word.Range r = WordDoc.Range(ref onewstart, ref onewe);    
            //object rText = true;
            find = r.Find;
            find.Text = "Rest";
            r.Find.Font.Underline = Word.WdUnderline.wdUnderlineSingle;
            r.Find.Font.Bold = 1;
            find.Execute(ref oMissing, ref matchword, ref matchwholeword, ref matchwildcards, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            if (find.Found)
            {
                Word.Table oTable;
                Word.Range newrng;
                int i = r.Start;
                object o = r.Start;
                object e = r.End;
                newrng = WordDoc.Range(ref o, ref e);
                string te = newrng.Text;
                oTable = WordDoc.Tables.Add(newrng, 1, 1, ref oMissing, ref oMissing);
                oTable.Columns.Item(1).Cells.Item(1).Range.Text = te;
                oTable.Rows.Item(1).Range.Bold = 1;
                oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
                oTable.Cell(1, 1).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;
                //  Word.Range newr;
                object os = oTable.Range.End;
                object oe = oTable.Range.End + 1;
                WordDoc.Range(ref os, ref oe).Font.Size = 2;
            }


like this u can able to change the FOnt Style of Word
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900