Microsoft Interop查找并替换为格式



我正在制作一个windows表单应用程序,它将接收用户输入,提交后将打开一个单词模板,并从windows表单中查找日期并将其替换为单词文档。我希望替换后的文本加下划线。我正在使用从另一个用户那里找到的函数,但我不确定如何设置格式。这是我正在使用的功能:


private void FindAndReplace(Microsoft.Office.Interop.Word.Application wordApp, object toFindText, object replaceWithText)
{
object matchCase = true;
object matchwholeWord = true;
object matchwildCards = false;
object matchSoundLike = false;
object nmatchAllforms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiactitics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = -2;
object wrap = 1;
wordApp.Selection.Find.Execute(ref toFindText, ref matchCase,
ref matchwholeWord, ref matchwildCards, ref matchSoundLike,
ref nmatchAllforms, ref forward,
ref wrap, ref format, ref replaceWithText,
ref replace, ref matchKashida,
ref matchDiactitics, ref matchAlefHamza,
ref matchControl);
}

我可以看到有一个对象format=false,但当我检查文档时,我不知道如何设置格式选项。

我找到了一个解决方案。我刚刚在上面使用的函数中添加了一行代码,在下面

wordApp.Selection.Find.Execute(ref toFindText, ref matchCase,
ref matchwholeWord, ref matchwildCards, ref matchSoundLike,
ref nmatchAllforms, ref forward,
ref wrap, ref format, ref replaceWithText,
ref replace, ref matchKashida,
ref matchDiactitics, ref matchAlefHamza,
ref matchControl);

我添加了

wordApp.Selection.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineSingle;

最新更新