2015-04-03 90 views
8

我有一個MigraDoc表,其中我指定的行高爲0.75cm,並且文本在單元格中間垂直對齊。當我將cell.Format.Shading.Color設置爲非白色時,邊框附近仍有一部分單元在所有四條邊上顯示爲白色。如何在MigraDoc表中設置單元格的背景色

我發現我可以通過設置column.LeftPadding = 0和column.RightPadding = 0刪除文本的左側和右側的白色部分。但是,我無法弄清楚如何獲得白色條紋在頂部/文本底部消失而不影響文本的垂直對齊。如果我將段落線高度更改爲0.75釐米,則條紋會消失,但文本會在單元格內向下對齊。我無法設置列着色顏色,因爲列中的每個單元格都包含不同的顏色。有沒有人知道一種方法來強制該段落垂直填充單元格(或以其他方式使背景顏色在單元格內均勻)?

這裏是我的代碼示例(在C#),其中表型MigraDoc.DocumentObjectModel.Tables.Table的:

... 

// Add a column at index #2 
var column = table.AddColumn(); 
column.LeftPadding = 0; 
column.RightPadding = 0; 

// Add more columns 
... 

// Iterate through the data printed in each row 
foreach (var rowData in myData) 
{ 
    // Create a row for the data 
    var row = table.AddRow(); 
    row.Height = ".75cm"; 
    row.Format.Font.Size = 11; 
    row.VerticalAlignment = VerticalAlignment.Center; 

    ... 

    // The following is for illustrative purposes... the actual 
    //  colors and text is determined by the data within the cell 
    var cell = row.Cells[2]; 
    cell.Format.Shading.Color = Colors.Black; 
    cell.Format.Font.Color = Colors.White; 
    var paragraph = cell.AddParagraph("Example"); 

    ... 
} 

回答

14

嘗試cell.Shading.Color,而不是cell.Format.Shading.Color - 前者設置單元格的顏色,後者設置文本背景的顏色(並且單元格的填充將具有不同的顏色)。

+0

我知道必須有一種方法來正確地做到這一點。我的黑客解決方法是添加一個段落並設置兩段的行高,直到垂直對齊匹配並且單元格完全填充。 – 2015-04-06 15:31:18

相關問題