Reporting

Wordize Reporting for .NET allows you to build reports using LINQ Reporting Engine.
Supported Modules and Document Formats

Wordize supports building reports in any format:

  • to build a report, use the Wordize Reporting for .NET module
  • to work with documents in the required formats, select the appropriate document conversion module

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.

Create a Template

First you need to create a template. A typical LINQ template consists of common document content and simple text placeholders of the following format: <<[field_name_]>>.

This is an example for a document with the common text “Name:” and “Age:” and their corresponding placeholders:

Name: <<[manager.Name]>>
Age: <<[manager.Age]>>

You can also create placeholders not only for text data but also for images. This is an example of converting a template with image and text fields into a resulting document with specific values:

Build a report using LINQ
Templates

Look at the templates for building a report using the LINQ Reporting Engine:

Create a Data Source

Next you need to create a data source. To build reports with Wordize.Reporting, you can use CsvDataSource, JsonDataSource, and XmlDataSource.

The following code examples show how to create a data source using:

  • CSV and the CsvDataSource method:

    public CsvDataSource(string csvPath)

  • Json and the JsonDataSource method:

    public CsvDataSource(string csvPath)

  • Xml and the XmlDataSource method:

    public XmlDataSource(string xmlPath)

Build a Report

Finally, you can build a report using your template and data source.

To build a report with LINQ syntax, use the one of the following JSON, XML, or Class data source as an example, and one of the BuildReport methods:

  • 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; }
    }

The following code example shows how to load data from JSON and then build a report:

// 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);

You can also 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" });

Use 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:

  • 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.

The following code example shows how to specify that missing object members should be treated as null literals by the engine:

// 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);

The following code example shows how to remove 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();

See Also