Generating reports using the Report Engine |
Docentric Toolkit Help
Send Feedback |
To use the Docentric Toolkit Report Engine from a .Net assembly the Report Engine assembly must first be referenced.
The Report Engine is represented by the Docentric.Word.DocumentGenerator class. In order to generate a document using the DocumentGenerator class follow these steps:
-
Obtain the objects/values needed for each data source defined by the document template. Different kinds of data sources require
different types of objects to be passed as values for the defined data sources:
-
For the .Net Object kind of a data source the object can be any type of .Net object. The following code segment loads a collection of Customer objects
from the database.
-
For the XML kind of a data source the object can be an instance of type XDocument or XElement from
the namespace System.Xml.Linq.
The following code segment loads an XML file containing customers data.
-
For the .Net Object kind of a data source the object can be any type of .Net object. The following code segment loads a collection of Customer objects
from the database.
-
Create an instance of the DocumentGenerator class using the constructor that accepts the value for the
default data source.
-
If a report template also defines named data sources, You must set values (objects) for them as well.
The first parameter is the name of the named data source (set on the template), while the other one is the value for the data source.dg.SetNamedDataSourceValue("Products", products); -
Optionally, if you want to interfere into the generation process to override elements' values or changing elements' properties before they take effect on the rendered document,
you can subscribe to the DocumentGenerator.ElementInitialize event. This event is raised for each Docentric element instance in the
report. It is mostly used for advanced data shaping and overwriting values (initially set as a result of data binding during document generation) or setting values
for the unbound Docentric elements.
dg.ElementInitialize += new ElementInitializeHandler(dg_ElementInitialize); void dg_ElementInitialize(object sender, ElementInitializeEventArgs e) { ... }
-
On the DocumentGenerator instance call the GenerateDocument method. This method accepts the report template argument
and the output document argument. According to your needs you can choose among two ovrloads:
one that accepts Stream objects:
and another one that accepts file paths:DocumentGenerationResult result = dg.GenerateDocument(templateStream, outputStream); -
Optionally, you can check the result returned from the DocumentGenerator method to check for any errors or warnings that might occured during the
document generation.