这是一个使用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();
}
}
结果如下:
为什么只有Hello, World!!
以粗体显示而不是Hello, World??
?使用Selection.Range.Bold
和Selection.Font.Bold
有什么区别?