C# 应用表样式时遇到的问题

C# 应用表样式时遇到的问题,c#,openxml,C#,Openxml,我试图在OpenXMLWord中将表样式应用于表 我看了几个例子,但我不明白为什么表样式没有出现。。。我查过其他帖子,比如 代码如下: public Table CreateTable(string tableStyle, Headings headingsList) { Table table = new Table(); // Set the Style TableProperties tblProps = new TableProperties(); Ta

我试图在OpenXMLWord中将表样式应用于表

我看了几个例子,但我不明白为什么表样式没有出现。。。我查过其他帖子,比如

代码如下:

public Table CreateTable(string tableStyle, Headings headingsList)
{
    Table table = new Table();

    // Set the Style
    TableProperties tblProps = new TableProperties();
    TableStyle tblStyle = new TableStyle() { Val = "LightGrid-Accent4" };
    TableWidth tblWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct};

    // TODO: Requires a class and remove hardcoding
    TableLook tblLook = new TableLook() { FirstRow = true, LastRow = false, FirstColumn = false, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true };

    tblProps.TableStyle = tblStyle;
    tblProps.TableWidth = tblWidth;
    table.Append(tblProps);

    TableRow tr = new TableRow();
    foreach (Heading heading in headingsList)
    {
        TableCell tc = new TableCell();
        TableCellWidth tcw = new TableCellWidth() { Width = heading.Width.ToString(), Type = TableWidthUnitValues.Pct };
        tc.Append(tcw);

        tc.Append(new Paragraph(new Run(new Text(heading.Title))));
        tr.Append(tc);
    }
    table.Append(tr);

    return table;
}
我查看了OpenXML工具,并查看了生成的文档,该文档看起来也不错。但是,在文档中,表没有格式化


如果您有任何想法,我们将不胜感激。

您是在创建一个全新的文件还是在更新现有的文件?可能是您所指的样式在文档中不存在-有关详细信息,请参阅。谢谢。我正在更新一个现有文件。我正在应用的表格样式是现有的。我使用了OpenXML工具(反射代码)中的id,因此它确实存在。有趣的是,当我创建自定义样式时,它找到并应用了它。我仍在调查为什么内置样式似乎不起作用。