2015-10-14 55 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,那麼它將只顯示文本。

雖然我已經解決了它,如果有人可以請解釋爲什麼發生這種情況,那將是非常感激。