/// <summary> /// The write table. /// </summary> /// <param name="t">The t.</param> public void WriteTable(Table t) { this.body.AppendChild(CreateParagraph(t.GetFullCaption(this.style), TableCaptionId)); var table = new DocumentFormat.OpenXml.Wordprocessing.Table(); var tableProperties1 = new TableProperties(); var tableStyle1 = new TableStyle { Val = "TableGrid" }; var tableWidth1 = new TableWidth { Width = "0", Type = TableWidthUnitValues.Auto }; var tableLook1 = new TableLook { Val = "04A0", FirstRow = true, LastRow = false, FirstColumn = true, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true }; tableProperties1.AppendChild(tableStyle1); tableProperties1.AppendChild(tableWidth1); tableProperties1.AppendChild(tableLook1); var tableGrid1 = new TableGrid(); // ReSharper disable once UnusedVariable foreach (var tc in t.Columns) { // TODO: use tc.Width to set the width of the column var gridColumn1 = new GridColumn { Width = "3070" }; tableGrid1.AppendChild(gridColumn1); } foreach (var row in t.Rows) { var tr = new TableRow(); if (row.IsHeader) { var trp = new TableRowProperties(); var tableHeader1 = new TableHeader(); trp.AppendChild(tableHeader1); tr.AppendChild(trp); } int j = 0; foreach (var c in row.Cells) { bool isHeader = row.IsHeader || t.Columns[j++].IsHeader; var cell = new TableCell(); var tcp = new TableCellProperties(); var borders = new TableCellBorders(); borders.AppendChild( new BottomBorder { Val = BorderValues.Single, Size = 4U, Space = 0U, Color = "auto" }); borders.AppendChild( new TopBorder { Val = BorderValues.Single, Size = 4U, Space = 0U, Color = "auto" }); borders.AppendChild( new LeftBorder { Val = BorderValues.Single, Size = 4U, Space = 0U, Color = "auto" }); borders.AppendChild( new RightBorder { Val = BorderValues.Single, Size = 4U, Space = 0U, Color = "auto" }); tcp.AppendChild(borders); cell.AppendChild(tcp); string styleId = isHeader ? "TableHeader" : "TableText"; cell.AppendChild(CreateParagraph(c.Content, styleId)); tr.AppendChild(cell); } table.AppendChild(tr); } this.body.AppendChild(table); }