Search code examples
vb.netnovacode-docx

Novacode docx - add style to table


I am using Novacode Docx to build a document based on webpage responses and need to know how \ where to apply a style to my table.

Happy to take answers in both VB and C#

this is what I have so far to build up the table and output it to the document

Dim columnNames As IEnumerable(Of String)
Dim tbl As Table = doc.AddTable(glossTable.Rows.Count - 1, glossTable.Columns.Count - 1)
columnNames = glossTable.Columns.Cast(Of DataColumn)().[Select](Function(column) column.ColumnName)
For i = 0 To columnNames.Count - 1
    tbl.Rows(0).Cells(i).Paragraphs.First().AppendLine(columnNames(i))
Next
For col = 0 To columnNames.Count - 1
    tbl.Rows(1).Cells(col).Paragraphs.First().AppendLine(gtRow(col))
Next

Solution

  • There is an enum of available table designs that can be used. The names should match the styles in MS Word.

    Example:

    tbl.Design = TableDesign.LightShadingAccent1