//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 (FileStream inputStream = new FileStream(sourceDocumentPath, FileMode.Open, FileAccess.Read))
{
using (Document document = generator.DocumentFactory(inputStream))
{
Dictionary<string, ReplacementItem> replacement =
new Dictionary<string, ReplacementItem>
{
{
"[ReplaceMe]",
new ReplacementItem {Value = "This is a test"}
}
};
generator.Replace(document, replacement);
using (FileStream outputStream = new FileStream(outputDocumentPath, FileMode.Create, FileAccess.Write))
{
generator.SaveDocument(document, outputStream);
}
}
}