【问题标题】:Microsoft Interop Find and Replace with FormattingMicrosoft 互操作查找和替换格式
【发布时间】:2022-10-05 02:12:32
【问题描述】:

我正在制作一个 Windows 窗体应用程序,它将接受用户输入,并在提交时打开一个 word 模板并从 windows 窗体中查找和替换日期到 word 文档。我希望替换的文本带有下划线。我正在使用从另一个用户那里找到的功能,但我不确定如何设置格式。这是我正在使用的功能:


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);
}

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

【问题讨论】:

    标签: c# winforms ms-word office-interop office-automation


    【解决方案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);
    

    我添加了

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

    【讨论】:

      猜你喜欢
      • 2013-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多