Word Reports
GenerateWordReport(Stream,Stream,List<Dictionary<String,ReplacementItem>>) Method
Example 



KellermanSoftware.WordReports Namespace > WordReportsGenerator Class > GenerateWordReport Method : GenerateWordReport(Stream,Stream,List<Dictionary<String,ReplacementItem>>) Method
The stream with a docx file to use as a template for the report
The output stream for the docx file
Replacement values
Replace items in the source document and create a new multi-page word document
Syntax
Public Overloads Sub GenerateWordReport( _
   ByVal sourceDocumentStream As Stream, _
   ByVal outputDocumentStream As Stream, _
   ByVal replacement As List(Of Dictionary(Of String,ReplacementItem)) _
) 
Dim instance As WordReportsGenerator
Dim sourceDocumentStream As Stream
Dim outputDocumentStream As Stream
Dim replacement As List(Of Dictionary(Of String,ReplacementItem))
 
instance.GenerateWordReport(sourceDocumentStream, outputDocumentStream, replacement)

Parameters

sourceDocumentStream
The stream with a docx file to use as a template for the report
outputDocumentStream
The output stream for the docx file
replacement
Replacement values
Example
//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);
 
using (FileStream inputStream = new FileStream(sourceDocumentPath, FileMode.Open, FileAccess.Read))
{
    using (FileStream outputStream = new FileStream(outputDocumentPath, FileMode.Create, FileAccess.Write))
    {
        generator.GenerateWordReport(inputStream,
                                     outputStream,
                                     list);
    }
}
'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)
 
Using inputStream As New FileStream(sourceDocumentPath, FileMode.Open, FileAccess.Read)
    Using outputStream As New FileStream(outputDocumentPath, FileMode.Create, FileAccess.Write)
        generator.GenerateWordReport(inputStream, outputStream, list)
    End Using
End Using
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

WordReportsGenerator Class
WordReportsGenerator Members
Overload List