Pages

Tuesday, November 20, 2012

Find and Replace in Word using C# .NET

A code sample for reference: Function 


 private void FindAndReplace(Microsoft.Office.Interop.Word.Application WordApp, object findtext, object replacewithText)
        object matchcase = true;
        object wrap = 1;
        WordApp.Selection.Find.Execute(ref findtext,
        WordApp.Selection.Find.Execute(ref findtext,


    {

        object matchwholeWord = true;
        object matchWildcard = false;
        object matchSoundsLike = false;
        object nmatchAllWordforms = false;
        object forword = true;
        object format = false;
        object matchKashida = false;
        object matchAlefHamza = false;
        object matchDiacritics = false;
        object matchControl = false;
        object read_only = false;
        object visible = true;
        object replace = 2;

        WordApp.Selection.Find.Replacement.ClearFormatting();
        WordApp.Selection.Find.ClearFormatting();
        WordApp.Selection.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

            ref matchcase, ref matchwholeWord,
            ref matchWildcard, ref matchSoundsLike,
            ref nmatchAllWordforms, ref forword,
            ref wrap, ref format, ref replacewithText,
            ref replace, ref matchKashida,
            ref matchDiacritics, ref matchAlefHamza,
            ref matchControl);
    }

No comments:

Post a Comment