2015-10-14 100 views
0

我正在建立一个word文档的编程方式,最后我要做的是添加一个标题,其中包含一个图像左侧的标题在中间。添加多个项目到标题Microsoft.Office.Interop.Word

我尝试了各种不同的东西,但没有任何工作。我已经尝试向表头添加一个表头(这引发了一个异常)。我试图添加图像,然后添加文本,但这只是使文本出现,而不是图像。我曾尝试将新字段添加到标题范围,但这也不起作用。

难道有人指出我正确的方向吗?

//Add header into the document 
foreach (Section section in document.Sections) 
{ 
    //Get the header range and add the header details. 
    Range headerRange = section.Headers 
    [WdHeaderFooterIndex.wdHeaderFooterPrimary].Range; 
    headerRange.InlineShapes.AddPicture(@"C:\Development\Tools\CommentParser\CommentParser\HeaderLogo.png"); 
    headerRange.Font.ColorIndex = WdColorIndex.wdBlue; 
    headerRange.Font.Size = 10; 
    headerRange.Text = "Title"; 
} 

回答

0

我找到了解决我的问题的方法。如果你问我,但是如果你在图像之前有headerRange.Text,那么它会显示它们并且文本将在图像的右侧,这是相当愚蠢的。如果我在示例文本中使用headerRange.Text,那么它将只显示文本。

虽然我已经解决了它,如果有人可以请解释为什么发生这种情况,那将是非常感激。