//To run this example code, create a word document called ExampleTemplate.docx with the text [ReplaceMe] 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\ExampleTemplate.docx";
const string outputDocumentPath = "ExampleOutput.docx";
using (Document document = generator.DocumentFactory(sourceDocumentPath))
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("FirstName", typeof(string));
dataTable.Columns.Add("LastName", typeof(string));
dataTable.Columns.Add("Salary", typeof(decimal));
dataTable.Rows.Add("John", "Smith", 30000M);
dataTable.Rows.Add("Joe", "Jones", 45000M);
List<ColumnDefinition> columnDefinitions =
new List<ColumnDefinition>
{
new ColumnDefinition("LastName"),
new ColumnDefinition("FirstName"),
new ColumnDefinition("Salary")
{
AddTotalAtTheEnd = true
}
};
Dictionary<string, ReplacementItem> replacement =
new Dictionary<string, ReplacementItem>
{
{
"[ReplaceMe]",
new ReplacementItem {Value = dataTable, ColumnDefinitions = columnDefinitions}
}
};
generator.Replace(document, replacement);
generator.SaveDocument(document, outputDocumentPath);
}