为什么在从 C# 添加新文本时关闭粗体不起作用?

Why does turning bold off not work when adding new text from C#?

我想将 C# 中的文本添加到 Winword 文档并打开或关闭粗体。

使用这个,abc 显示为粗体。然后以编程方式关闭粗体,因此当直接在 Winword 中键入时,以下文本显示为非粗体。

{
    objWinWordControl.document.Application.Selection.Font.Bold = 1;
    objWinWordControl.document.Application.Selection.Text = "abc";
    objWinWordControl.document.Application.Selection.EndKey(Word.WdUnits.wdStory, Word.WdMovementType.wdMove);

    objWinWordControl.document.Application.Selection.Font.Bold = 0;
    // continue typing text in Winword now, the text isn't bold
}

这里加粗abcxyz,虽然加粗已经关闭了

{
    objWinWordControl.document.Application.Selection.Font.Bold = 1;
    objWinWordControl.document.Application.Selection.Text = "abc";

    objWinWordControl.document.Application.Selection.EndKey(Word.WdUnits.wdStory, Word.WdMovementType.wdMove);

    objWinWordControl.document.Application.Selection.Font.Bold = 0;

    // this text is bold, although bold  had been turned off
    objWinWordControl.document.Application.Selection.Text = "xyz"; 
}

为什么以编程方式添加时 "xyz" 是粗体?

我现在找到了这样的解决方法:

{
    object start = 0;
    object end = 0;

    Word.Range rng = objWinWordControl.document.Range(ref start, ref end);
    rng.Text = "abc";
    rng.Font.Bold = 1;

    start = rng.Text.Length;
    end = rng.Text.Length;

    rng = objWinWordControl.document.Range(ref start, ref end);
    rng.Text = "xyz";
    rng.Font.Bold = 0;
}

但相比于:

 objWinWordControl.document.Application.Selection.Text = "abc";

性能很差