Deutsch Indonesia Tiếng Việt فارسی English Italiano Türkçe ไทย Español Polski Русский 日本語 Français Português العربية

Generate Word Documents from Templates using C#

Wordize for .NET is a professional solution for automated reporting and programmatic Word document generation. The ReportBuilder class provides C# developers with comprehensive capabilities for creating Word reports using templates and LINQ syntax, helping accelerate business analytics processes and integrate dynamic content into automated document workflows.

Key Features:
  • Programmatic Word document generation - the ReportBuilder class provides the BuildReport() method to generate Word documents from templates
  • Flexible data source integration - supports JSON, XML, CSV, and programmatic objects (custom classes, object collections)
  • LINQ expressions for data filtering, sorting, and grouping during Word document generation
  • Customizable generation parameters - the ReportBuilderOptions class manages available data types, missing field handling, empty paragraph removal, and other Word document creation settings
  • Export to image format - the BuildReportToImages() method returns Word report pages as an image array
  • Fluent API support for report generation operations through ReportBuilderContext and method chaining, enhancing C# code readability

LINQ Reporting enables creation of professional Word documents with support for complex formatting, tables, and charts. Word files maintain editability, making them ideal for corporate documentation, contracts, and technical specifications.

Test the capabilities of programmatic Word document generation in the interactive online demo presented on this page. Upload a document template, load a data file (JSON, XML, or CSV), run the operation, and download the generated Word document for review. The provided C# code snippet is fully ready for use in your .NET project.

C#
Run code
Upload document template
Upload data file
Select output format from the list
using Wordize.Reporting;

var dataSource = new JsonDataSource("data.json");
ReportBuilder.BuildReport("Input.docx", "Output.docx", dataSource, "");
using Wordize.Reporting; var dataSource = new JsonDataSource("data.json"); ReportBuilder.BuildReport("Input.docx", "Output.docx", dataSource, ""); using Wordize.Reporting; using Wordize.Saving; var dataSource = new JsonDataSource("data.json"); var imageStreams = ReportBuilder.BuildReportToImages("Input.docx", new ImageSaveOptions(SaveFormat.Docx), new[] { dataSource }, new[] { "" }); foreach (var (stream, page) in imageStreams.Select((s, i) => (s, i))) { using var _ = stream; stream.Position = 0; using var file = File.Create($"Output_{page + 1}.docx"); stream.CopyTo(file); }
using Wordize.Reporting;

var dataSource = new XmlDataSource("data.xml");
ReportBuilder.BuildReport("Input.docx", "Output.docx", dataSource, "");
using Wordize.Reporting; var dataSource = new XmlDataSource("data.xml"); ReportBuilder.BuildReport("Input.docx", "Output.docx", dataSource, ""); using Wordize.Reporting; using Wordize.Saving; var dataSource = new XmlDataSource("data.xml"); var imageStreams = ReportBuilder.BuildReportToImages("Input.docx", new ImageSaveOptions(SaveFormat.Docx), new[] { dataSource }, new[] { "" }); foreach (var (stream, page) in imageStreams.Select((s, i) => (s, i))) { using var _ = stream; stream.Position = 0; using var file = File.Create($"Output_{page + 1}.docx"); stream.CopyTo(file); }
using Wordize.Reporting;

var dataSource = new CsvDataSource("data.csv", new CsvDataLoadOptions() { HasHeaders = true });
ReportBuilder.BuildReport("Input.docx", "Output.docx", dataSource, "");
using Wordize.Reporting; var dataSource = new CsvDataSource("data.csv", new CsvDataLoadOptions() { HasHeaders = true }); ReportBuilder.BuildReport("Input.docx", "Output.docx", dataSource, ""); using Wordize.Reporting; using Wordize.Saving; var dataSource = new CsvDataSource("data.csv", new CsvDataLoadOptions() { HasHeaders = true }); var imageStreams = ReportBuilder.BuildReportToImages("Input.docx", new ImageSaveOptions(SaveFormat.Docx), new[] { dataSource }, new[] { "" }); foreach (var (stream, page) in imageStreams.Select((s, i) => (s, i))) { using var _ = stream; stream.Position = 0; using var file = File.Create($"Output_{page + 1}.docx"); stream.CopyTo(file); }
Run code

How to create Word report in C#

  1. Connect the Wordize SDK to your .NET project
  2. Create a data source and call the ReportBuilder.BuildReport() method, specifying the Word template, result file and data source in parameters
  3. Get the generated Word document
5%