Word Reports
Inserting Tables
Basic Tasks > Inserting Tables

Tables have default formatting.  Defaults can be overridden with column definitions.  Here is an example of inserting a table into a Word Document:

 

C#
//To run this example code, create a word document called SimpleTable.docx with the text [SimpleTable] in the document
 

WordReportsGenerator generator = new WordReportsGenerator(); //Trial Mode

//WordReportsGenerator generator = new WordReportsGenerator("place user name here", "place license key here"); //License Mode

const string sourceDocumentPath = @"Test Documents\SimpleTable.docx";

const string outputDocumentPath = "ReplaceSimpleTable.docx";

DataTable simpleTable = new DataTable();

simpleTable.Columns.Add("FirstName", typeof(string));

simpleTable.Columns.Add("LastName", typeof(string));

simpleTable.Rows.Add("Greg", "Finzer");

simpleTable.Rows.Add("Oreo", "Finzer");

Dictionary<string, ReplacementItem> replacement =

new Dictionary<string, ReplacementItem>

{

{

"[SimpleTable]",

new ReplacementItem {Value = simpleTable}

}

};

 

generator.GenerateWordReport(sourceDocumentPath,

outputDocumentPath,

replacement);

 

VB.NET
'To run this example code, create a word document called SimpleTable.docx with the text [SimpleTable] in the document
 

Dim generator As New WordReportsGenerator() 'Trial Mode

'WordReportsGenerator generator = new WordReportsGenerator("place user name here", "place license key here"); //License Mode

 

Const sourceDocumentPath As String = "Test Documents\SimpleTable.docx"

Const outputDocumentPath As String = "ReplaceSimpleTable.docx"

 

Dim simpleTable As New DataTable()

simpleTable.Columns.Add("FirstName", GetType(String))

simpleTable.Columns.Add("LastName", GetType(String))

simpleTable.Rows.Add("Greg", "Finzer")

simpleTable.Rows.Add("Oreo", "Finzer")

 

Dim replacement As New Dictionary(Of String, ReplacementItem) From {

{

"[SimpleTable]", New ReplacementItem With {.Value = simpleTable}

}

}

 

generator.GenerateWordReport(sourceDocumentPath, outputDocumentPath, replacement)