为什么`Selection.Font.Bold = 1`按预期工作但不是'Selection.Range.Bold = 1`(Word Interop)

时间:2016-12-16 17:03:40

标签: c# ms-word office-interop

这是一个使用Word Interop的C#程序:

using Microsoft.Office.Interop.Word;

class Program
{
    static void Main(string[] args)
    {
        Application app = new Application();
        app.Visible = true;
        Document doc = app.Documents.Add(Visible: true);

        Selection selection = app.Selection;
        selection.TypeText("Hello, friend");
        selection.TypeParagraph();
        selection.Range.Bold = 1;
        selection.TypeText("Hello, world??");
        selection.TypeParagraph();
        selection.Font.Bold = 1;
        selection.TypeText("Hello, world!!");
        selection.TypeParagraph();
    }
}

结果如下:

Resulting Word document

为什么只有Hello, World!!以粗体显示而不是Hello, World???使用Selection.Range.BoldSelection.Font.Bold有什么区别?

0 个答案:

没有答案