尝试使用打开的xml更改Word文档中表格单元格的字体颜色

时间:2020-01-01 18:03:08

标签: c# .net ms-word openxml openxml-sdk

我正在尝试使用下图所示的单元格创建一个表,同时使用Open XML生成Word文档,

enter image description here

为此,我编写了这样的代码

        TableRow tr = new TableRow();
        // Create a cell.
        TableCell tc1 = new TableCell();
        // Specify the width property of the table cell.
        tc1.Append(new TableCellProperties(
            new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));

        tc1.TableCellProperties.Shading = new Shading()
        {                
            Fill = "#5DBCD2",                
        };
        Paragraph systemPara = new Paragraph();
        Run firstColumn = systemPara.AppendChild(new Run());
        RunProperties runProps = new RunProperties();
        Bold fontBoldForRunProps = new Bold();
        Text fontText = new Text("System");
        Color fontColor = new Color() { Val = "#FFFFFF" };
        runProps.Append(fontBoldForRunProps);
        runProps.Append(fontText);
        runProps.Append(fontColor);
        firstColumn.Append(runProps);
        tc1.Append(systemPara);
        tr.Append(tc1);

以某种方式,我无法将字体颜色设置为white,结果像文本System的字体颜色一样变成黑色。

有人可以向我指出上面代码在哪里做错了正确的方向。

非常感谢。

0 个答案:

没有答案