颜色填写表第一行openxml c#.net Microsoft Word [英] Color fill in Table first row openxml c#.net microsoft word
本文介绍了颜色填写表第一行openxml c#.net Microsoft Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
以下是我在C#.net中Microsoft Word的openxml中的表生成代码
我可以在MS Office中创建表格,但必须在表格的第一行中填充背景色.
但无法找到解决方案.
请让我知道如何在表格的第一行中用粗体填充相同的颜色.
在此先感谢...
Hi All
Below is my table generation code in openxml for Microsoft word in C#.net
I am able to create the table in MS office but I have to fill the background color in my first row of table.
But unable to find out the solution.
Please let me know how do i fill the same color still with bold character in first row of table.
Thanks in Advance...
using (WordprocessingDocument doc
= WordprocessingDocument.Open(fileName, true))
{
// Create an empty table.
Table table = new Table();
// Create a TableProperties object and specify its border information.
TableProperties tblProp = new TableProperties(
new TableBorders(
new TopBorder()
{
Val =
new EnumValue<BorderValues>(BorderValues.Single),
Size = 1
},
new BottomBorder()
{
Val =
new EnumValue<BorderValues>(BorderValues.Single),
Size = 1
},
new LeftBorder()
{
Val =
new EnumValue<BorderValues>(BorderValues.Single),
Size = 1
},
new RightBorder()
{
Val =
new EnumValue<BorderValues>(BorderValues.Single),
Size = 1
},
new InsideHorizontalBorder()
{
Val =
new EnumValue<BorderValues>(BorderValues.Single),
Size = 1
},
new InsideVerticalBorder()
{
Val =
new EnumValue<BorderValues>(BorderValues.Single),
Size = 1
}
)
);
table.AppendChild<TableProperties>(tblProp);
var tr = new TableRow();
var tc1 = new TableCell();
tc1.Append(new Paragraph(new Run(new Text("S Name"))));
// Assume you want columns that are automatically sized.
tc1.Append(new TableCellProperties(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2000" }));
tr.Append(tc1);
推荐答案
您好,
我尝试了以下方法,效果很好.
我对您的代码进行了非常小的修改,以将阴影对象添加到tableCellProperties(tcp)
希望对您有所帮助.
瓦莱丽.
Hello,
I tried the following and it works well.
I have very slightly modified your code to add a Shading object to the tableCellProperties (tcp)
Hope it helps.
Valery.
var tr = new TableRow();
var tc1 = new TableCell();
tc1.Append(new Paragraph(new Run(new Text("S Name"))));
// Assume you want columns that are automatically sized.
var tcp = new TableCellProperties(new TableCellWidth()
{
Type = TableWidthUnitValues.Dxa,
Width = "2000",
});
// Add cell shading.
var shading = new Shading()
{
Color = "auto",
Fill = "ABCDEF",
Val = ShadingPatternValues.Clear
};
tcp.Append(shading);
tc1.Append(tcp);
tr.Append(tc1);
table.Append(tr);
这篇关于颜色填写表第一行openxml c#.net Microsoft Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文