我正在尝试将表样式应用于openxml word中的表。
我看过几个例子,但我很难理解为什么桌面风格没有出现......我已经检查了其他帖子,如Apply a TableStyle to a Word Table
这是代码:
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工具并看了一下生成的文档,看起来也不错。但是,在文档中,表格没有格式化。
任何想法都会受到赞赏。