Sometimes it is necessary to create multiple pages of invoices, packing slips etc. Create a word document to be used as a template with the desired tags to replace. Then create a list of dictionary replacement items to replace for each page.
C# | |
---|---|
//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"; List<Dictionary<string,ReplacementItem>> list = new List<Dictionary<string, ReplacementItem>>(); Dictionary<string, ReplacementItem> replacement1 = new Dictionary<string, ReplacementItem> { { "[ReplaceMe]", new ReplacementItem { Value = "This is a test" } } }; list.Add(replacement1); Dictionary<string, ReplacementItem> replacement2 = new Dictionary<string, ReplacementItem> { { "[ReplaceMe]", new ReplacementItem { Value = "This is a second test" } } }; list.Add(replacement2); generator.GenerateWordReport(sourceDocumentPath, outputDocumentPath, list); |
VB.NET | |
---|---|
'To run this example code, create a word document called ExampleTemplate.docx with the text [ReplaceMe] 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\ExampleTemplate.docx" Const outputDocumentPath As String = "ExampleOutput.docx" Dim list As New List(Of Dictionary(Of String,ReplacementItem))() Dim replacement1 As New Dictionary(Of String, ReplacementItem)() From {{ "[ReplaceMe]", New ReplacementItem With {.Value = "This is a test"} }} list.Add(replacement1) Dim replacement2 As New Dictionary(Of String, ReplacementItem)() From {{ "[ReplaceMe]", New ReplacementItem With {.Value = "This is a second test"} }} list.Add(replacement2) generator.GenerateWordReport(sourceDocumentPath, outputDocumentPath, list) |