搜索和替换word文档中的单词C#

时间:2015-04-10 15:29:54

标签: search checkbox replace ms-word

我想创建一个程序,我必须加载word文档,然后检查checkbox搜索和替换单词,然后单击一个按钮,然后搜索并替换它

我知道代码是:

private void SearchReplace()
{
    Word.Find findObject = Application.Selection.Find;
    findObject.ClearFormatting();
    findObject.Text = "find me";
    findObject.Replacement.ClearFormatting();
    findObject.Replacement.Text = "Found";

object replaceAll = Word.WdReplace.wdReplaceAll;
findObject.Execute(ref missing, ref missing, ref missing, ref missing, ref  missing,
    ref missing, ref missing, ref missing, ref missing, ref missing,
    ref replaceAll, ref missing, ref missing, ref missing, ref missing);
}

我如何将其加入checkbox

1 个答案:

答案 0 :(得分:0)

双击Protect按钮,将打开其方法。在其中,您可以放置​​任何您想要的代码。

首先检查是否选中了复选框,然后检查替换空格的代码:

 if (checkboxName.Checked == true)
   {
     SearchReplace();
   }