Reporting
Use the Wordize Reporting for .NET module to build reports using the LINQ Reporting Engine.
Select any document conversion module to work with the required formats.
Wordize offers a powerful LINQ reporting engine that enables developers to generate dynamic, data-driven documents efficiently. Using the Wordize Reporting for .NET module, you can populate templates with data from various sources, creating customized reports seamlessly.
How To Build a Report
LINQ is a .NET feature that allows to query data from various sources (like collections, databases, XML, and more) using a syntax integrated directly into the language. It provides a consistent and readable way to filter, sort, group, and manipulate data.
Using Wordize Reporting for .NET, you can extract and structure data using LINQ, then pass that data to a template document for generating dynamic reports. This approach is useful for creating customized invoices, summaries, and other data-driven documents.
The template is built using simple text placeholders of the following format: <<[field_name_]>>
. For example:
Name: <<[manager.Name]>>
Age: <<[manager.Age]>>

Look at the templates for building a report using the LINQ Reporting Engine:
Find code examples of building reports in the Reporting Code Examples section at the bottom of the page.
Reporting Options
Wordize allows you to customize the behavior of the report generation process, controlling how data is transformed for display in the output document.
Wordize supports the following ReportBuilderOptions options:
- KnownTypes – gets an unordered set containing Type objects, which fully or partially qualified names can be used within report templates
- MissingMemberMessage – specifies a string value printed instead of a reference to a missing object member (default is an empty string)
- Options – specifies a set of flags that control report rendering behavior
Code examples of building reports using these options can be found in the next section Reporting Code Examples.
Reporting Code Examples
Wordize provides both a Standard API and a Fluent API, allowing developers to choose the most convenient approach for their needs.
Wordize API
To build a report with LINQ syntax, use the Simple Reporting template and one of the BuildReport methods.
In the further examples, the following JSON, XML, or Class will be used as a data source:
JSON:
{
manager: {
Photo: "Photo.png",
Name: "John Smith",
Age: 37
}
}
XML:
<manager>
<Photo>Photo.png</Photo>
<Name>John Smith</Name>
<Age>37</Age>
</manager>
Class:
public class Manager
{
public string Photo { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
method BuildReport(string, string, object)
// Load data from JSON with AlwaysGenerateRootObject load option enabled.
JsonDataLoadOptions options = new JsonDataLoadOptions();
options.AlwaysGenerateRootObject = true;
JsonDataSource ds = new JsonDataSource("Data.json", options);
// Build the report.
ReportBuilder.BuildReport("ReportingTemplate.docx", "Report.1.docx", ds);
method BuildReport(string, string, SaveFormat, object)
// Load data from JSON with AlwaysGenerateRootObject load option enabled.
JsonDataLoadOptions options = new JsonDataLoadOptions();
options.AlwaysGenerateRootObject = true;
JsonDataSource ds = new JsonDataSource("Data.json", options);
// Build the report explicitly specifying the output save format.
ReportBuilder.BuildReport("ReportingTemplate.docx", "Report.2.docx", SaveFormat.Docx, ds);
method BuildReport(string, string, object, string)
// Load data from XML
XmlDataSource ds = new XmlDataSource("Data.xml");
// Build report explicatively specifying data source name.
ReportBuilder.BuildReport("ReportingTemplate.docx", "Report.3.docx", ds, "manager");
method BuildReport(string, string, SaveFormat, object, string)
// Load data from XML
XmlDataSource ds = new XmlDataSource("Data.xml");
// Build the report explicitly specifying the output save format and data source name.
ReportBuilder.BuildReport("ReportingTemplate.docx", "Report.4.docx", SaveFormat.Docx, ds, "manager");
method BuildReport(string, string, object[], string[])
// Use object as a data source.
Manager manager = new Manager() { Photo = "Photo.png", Name = "John Smith", Age = 37 };
object[] dataSources = new object[] { manager, "This is my title" };
string[] dataSourceNames = new string[] { "manager", "title" };
// Build report specifying array of data sources.
ReportBuilder.BuildReport("ReportingTemplate.docx", "Report.5.docx", dataSources, dataSourceNames);
method BuildReport(string, string, SaveFormat, object[], string[])
// Use object as a data source.
Manager manager = new Manager() { Photo = "Photo.png", Name = "John Smith", Age = 37 };
object[] dataSources = new object[] { manager, "This is my title" };
string[] dataSourceNames = new string[] { "manager", "title" };
// Build report specifying array of data sources.
ReportBuilder.BuildReport("ReportingTemplate.docx", "Report.6.docx", SaveFormat.Docx, dataSources, dataSourceNames);
method BuildReport(Stream, Stream, SaveFormat, object)
// Load data from JSON with AlwaysGenerateRootObject load option enabled.
JsonDataLoadOptions options = new JsonDataLoadOptions();
options.AlwaysGenerateRootObject = true;
JsonDataSource ds = new JsonDataSource("Data.json", options);
// Build the report loading template from stream and saving the output to stream.
using var streamIn = File.OpenRead("ReportingTemplate.docx");
using var streamOut = File.Create("Report.7.docx");
ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, ds);
method BuildReport(Stream, Stream, SaveFormat, object, string)
// Load data from XML
XmlDataSource ds = new XmlDataSource("Data.xml");
// Build the report loading template from stream and saving the output to stream.
using var streamIn = File.OpenRead("ReportingTemplate.docx");
using var streamOut = File.Create("Report.8.docx");
ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, ds, "manager");
method BuildReport(Stream, Stream, SaveFormat, object[], string[])
// Use object as a data source.
Manager manager = new Manager() { Photo = "Photo.png", Name = "John Smith", Age = 37 };
object[] dataSources = new object[] { manager, "This is my title" };
string[] dataSourceNames = new string[] { "manager", "title" };
// Build the report loading template from stream and saving the output to stream.
using var streamIn = File.OpenRead("ReportingTemplate.docx");
using var streamOut = File.Create("Report.9.docx");
ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, dataSources, dataSourceNames);
method BuildReport(string, string, object, ReportBuilderOptions)
// Load data from JSON with AlwaysGenerateRootObject load option enabled.
JsonDataLoadOptions jsonLoadOptions = new JsonDataLoadOptions();
jsonLoadOptions.AlwaysGenerateRootObject = true;
JsonDataSource ds = new JsonDataSource("Data.json", jsonLoadOptions);
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build the report.
ReportBuilder.BuildReport("ReportingTemplate.docx", "ReportOption.1.docx", ds, reportBuilderOptions);
method BuildReport(string, string, SaveFormat, object, ReportBuilderOptions)
// Load data from JSON with AlwaysGenerateRootObject load option enabled.
JsonDataLoadOptions jsonLoadOptions = new JsonDataLoadOptions();
jsonLoadOptions.AlwaysGenerateRootObject = true;
JsonDataSource ds = new JsonDataSource("Data.json", jsonLoadOptions);
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build the report explicitly specifying the output save format.
ReportBuilder.BuildReport("ReportingTemplate.docx", "ReportOption.2.docx", SaveFormat.Docx, ds, reportBuilderOptions);
method BuildReport(string, string, object, string, ReportBuilderOptions)
// Load data from XML
XmlDataSource ds = new XmlDataSource("Data.xml");
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build report explicatively specifying data source name.
ReportBuilder.BuildReport("ReportingTemplate.docx", "ReportOption.3.docx", ds, "manager", reportBuilderOptions);
method BuildReport(string, string, SaveFormat, object,string, ReportBuilderOptions)
// Load data from XML
XmlDataSource ds = new XmlDataSource("Data.xml");
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build the report explicitly specifying the output save format and data source name.
ReportBuilder.BuildReport("ReportingTemplate.docx", "ReportOption.4.docx", SaveFormat.Docx, ds, "manager", reportBuilderOptions);
method BuildReport(string, string, object[], string[], ReportBuilderOptions)
// Use object as a data source.
Manager manager = new Manager() { Photo = "Photo.png", Name = "John Smith", Age = 37 };
object[] dataSources = new object[] { manager, "This is my title" };
string[] dataSourceNames = new string[] { "manager", "title" };
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build report specifying array of data sources.
ReportBuilder.BuildReport("ReportingTemplate.docx", "ReportOption.5.docx", dataSources, dataSourceNames, reportBuilderOptions);
method BuildReport(string, string, SaveFormat, object[], string[], ReportBuilderOptions)
// Use object as a data source.
Manager manager = new Manager() { Photo = "Photo.png", Name = "John Smith", Age = 37 };
object[] dataSources = new object[] { manager, "This is my title" };
string[] dataSourceNames = new string[] { "manager", "title" };
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build report specifying array of data sources.
ReportBuilder.BuildReport("ReportingTemplate.docx", "ReportOption.6.docx", SaveFormat.Docx, dataSources, dataSourceNames, reportBuilderOptions);
method BuildReport(Stream, Stream, SaveFormat, object, ReportBuilderOptions)
// Load data from JSON with AlwaysGenerateRootObject load option enabled.
JsonDataLoadOptions jsonLoadOptions = new JsonDataLoadOptions();
jsonLoadOptions.AlwaysGenerateRootObject = true;
JsonDataSource ds = new JsonDataSource("Data.json", jsonLoadOptions);
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build the report loading template from stream and saving the output to stream.
using var streamIn = File.OpenRead("ReportingTemplate.docx");
using var streamOut = File.Create("ReportOption.7.docx");
ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, ds, reportBuilderOptions);
method BuildReport(Stream, Stream, SaveFormat, object,string, ReportBuilderOptions)
// Load data from XML
XmlDataSource ds = new XmlDataSource("Data.xml");
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build the report loading template from stream and saving the output to stream.
using var streamIn = File.OpenRead("ReportingTemplate.docx");
using var streamOut = File.Create("ReportOption.8.docx");
ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, ds, "manager", reportBuilderOptions);
method BuildReport(Stream, Stream, SaveFormat, object[], string[], ReportBuilderOptions)
// Use object as a data source.
Manager manager = new Manager() { Photo = "Photo.png", Name = "John Smith", Age = 37 };
object[] dataSources = new object[] { manager, "This is my title" };
string[] dataSourceNames = new string[] { "manager", "title" };
ReportBuilderOptions reportBuilderOptions = new ReportBuilderOptions();
reportBuilderOptions.AllowMissingMembers = true;
// Build the report loading template from stream and saving the output to stream.
using var streamIn = File.OpenRead("ReportingTemplate.docx");
using var streamOut = File.Create("ReportOption.9.docx");
ReportBuilder.BuildReport(streamIn, streamOut, SaveFormat.Docx, dataSources, dataSourceNames, reportBuilderOptions);
method BuildReportToImages(string, ImageSaveOptions, object[], string[], ReportBuilderOptions)
You can populate a document template with data from multiple sources and render the output into images.
Manager manager = new Manager() { Name = "John Smith", Age = 37 };
Stream[] pages = ReportBuilder.BuildReportToImages("ReportingTemplate.docx", new ImageSaveOptions(SaveFormat.Png), new object[] { manager }, new string[] { "manager" });
method BuildReportToImages(Stream, ImageSaveOptions, object[], string[], ReportBuilderOptions)
Manager manager = new Manager() { Name = "John Smith", Age = 37 };
using var streamIn = File.OpenRead("ReportingTemplate.docx");
Stream[] pages = ReportBuilder.BuildReportToImages(inStream, new ImageSaveOptions(SaveFormat.Png), new object[] { manager }, new string[] { "manager" });
// ........................
Wordize Fluent API
Within the Fluent API, there is a context. ReportBuilderContext allows you to customize the report build process. Specify the following properties to add the context:
ReportBuilderOptions – specifies report build options:
- AllowMissingMembers – specifies that missing object members should be treated as null literals by the engine (if this option is not set, the engine throws an exception when encounters a missing object member)
- RemoveEmptyParagraphs – specifies that the engine should remove paragraphs becoming empty after template syntax tags are removed or replaced with empty values
- InlineErrorMessages – specifies that the engine should inline template syntax error messages into output documents (if this option is not set, the engine throws an exception when encounters a syntax error)
- RespectJpegExifOrientation – specifies that the engine should use EXIF image orientation values to appropriately rotate inserted JPEG images
- UpdateFieldsSyntaxAware – specifies that the engine should ignore template syntax in field results and update fields after a report is built
- KnownTypes – gets an unordered set (i.e. a collection of unique items) containing Type objects which fully or partially qualified names can be used within report templates processed by this engine instance to invoke the corresponding types’ static members, perform type casts, etc.
DataSources – specifies the data source to build a report. If you build a report without datasource, the Reporting Engine will simply interpret the syntax in the template.
You can build reports with or without context.
method to Build a Report, filling the the Simple Reporting template with data from the data class
ReportBuilderContext context = new ReportBuilderContext();
context.DataSources.Add(new DummyData() { Name = "John Smith", Age = "37" }, "manager");
ReportBuilder.Create(context)
.From("DocumentIn.docx")
.To("DocumentOut.docx")
.Execute();
public class DummyData
{
public string Name { get; set; }
public string Age { get; set; }
}
method to Build a Report that removes empty paragraphs generated during report building
ReportBuilderContext context = new ReportBuilderContext();
context.DataSources.Add(new DummyData() { Name = "John Smith", Age = "37" }, "manager");
context.ReportBuilderOptions.RemoveEmptyParagraphs = true;
ReportBuilder.Create(context)
.From("DocumentIn.docx")
.To("DocumentOut.docx")
.Execute();