Word Reports
Replace(Document,Dictionary<String,ReplacementItem>) Method
Example 



KellermanSoftware.WordReports Namespace > WordReportsGenerator Class > Replace Method : Replace(Document,Dictionary<String,ReplacementItem>) Method
Source document
Replacement values
Replace items in the source document
Syntax
Public Overloads Sub Replace( _
   ByVal document As Document, _
   ByVal replacement As Dictionary(Of String,ReplacementItem) _
) 
Dim instance As WordReportsGenerator
Dim document As Document
Dim replacement As Dictionary(Of String,ReplacementItem)
 
instance.Replace(document, replacement)
public void Replace( 
   Document document,
   Dictionary<string,ReplacementItem> replacement
)

Parameters

document
Source document
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";
 
using (Document document = generator.DocumentFactory(sourceDocumentPath))
{
    Dictionary<string, ReplacementItem> replacement =
        new Dictionary<string, ReplacementItem>
            {
                {
                    "[ReplaceMe]",
                    new ReplacementItem {Value = "This is a test"}
                }
            };
 
    generator.Replace(document, replacement);
 
    generator.SaveDocument(document, outputDocumentPath);
}
'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"
 
Using document As Document = generator.DocumentFactory(sourceDocumentPath)
    Dim replacement As New Dictionary(Of String, ReplacementItem)() From {{ "[ReplaceMe]", New ReplacementItem With {.Value = "This is a test"} }}
 
    generator.Replace(document, replacement)
 
    generator.SaveDocument(document, outputDocumentPath)
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