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

DOC Document Generation with Mail Merge in C#

Wordize for .NET is a professional solution for automated creation of personalized DOC documents using Mail Merge technology. The MailMerger class enables C# developers to merge ready-made document templates with data from various sources for bulk generation of personalized DOC invoices, contracts, reports, and letters.

Wordize for .NET provides the ability to use Mail Merge technology with templates in any supported formats. This allows creating personalized DOC documents regardless of the original template format.

Functional Capabilities:
  • Simple document population - the Execute() method generates personalized DOC documents by merging ready-made templates with external data sources
  • Dynamic content generation - the ExecuteWithRegions() method processes repeating template elements to create tables and lists of variable length in DOC format
  • Integration with various data sources - support for DataRow, DataTable, DataSet types, value arrays
  • Advanced settings - the MailMergeOptions class manages document generation parameters: removing empty paragraphs, unused regions and fields, trimming excess spaces, merging duplicate regions, and other parameters
  • Export to graphic format capability - the ExecuteToImages() method returns results as a set of images
  • Fluent API support for launching generation through MailMergerContext and method chaining, adding clarity to C# code
Use Case Scenarios:
  • Bulk mailing of personalized letters and notifications with individual recipient data
  • Creating personalized DOC invoices, contracts, and proposals with information specific to each client
  • Generating DOC documents from ready-made forms: certificates, references, invitations with personal data
  • Automated creation of uniform DOC documents with different content based on databases

Test the capabilities of programmatic generation of personalized documents using Mail Merge technology in the interactive online demo presented on this page. Upload a document template, a text file with data (CSV, JSON, XML), run the operation, and download the generated result for verification. The provided C# code snippet is fully ready for use in your .NET project.

C#
Run code
Upload document template
Upload data source
Select output format from the list
using System.Data;
using Newtonsoft.Json;
using Wordize.MailMerging;

string json = File.ReadAllText("DataSource.json");
DataTable dataTable = JsonConvert.DeserializeObject(json);
MailMerger.Execute("Input.doc", "Output.doc", SaveFormat.Doc, dataTable);
using System.Data; using Newtonsoft.Json; using Wordize.MailMerging; string json = File.ReadAllText("DataSource.json"); DataTable dataTable = JsonConvert.DeserializeObject(json); MailMerger.Execute("Input.doc", "Output.doc", SaveFormat.Doc, dataTable); using System.Data; using Newtonsoft.Json; using Wordize.MailMerging; using Wordize.Saving; string json = File.ReadAllText("DataSource.json"); DataTable dataTable = JsonConvert.DeserializeObject(json); var imageStreams = MailMerger.Execute("Input.doc", new ImageSaveOptions(SaveFormat.Doc), dataTable); 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}.doc"); stream.CopyTo(file); }
using System.Data;
using Wordize.MailMerging;

DataSet dataSet = new DataSet();
dataSet.ReadXml("DataSource.xml");
MailMerger.Execute("Input.doc", "Output.doc", SaveFormat.Doc, dataSet.Tables[0]);
using System.Data; using Wordize.MailMerging; DataSet dataSet = new DataSet(); dataSet.ReadXml("DataSource.xml"); MailMerger.Execute("Input.doc", "Output.doc", SaveFormat.Doc, dataSet.Tables[0]); using System.Data; using Wordize.MailMerging; using Wordize.Saving; DataSet dataSet = new DataSet(); dataSet.ReadXml("DataSource.xml"); var imageStreams = MailMerger.Execute("Input.doc", new ImageSaveOptions(SaveFormat.Doc), dataSet.Tables[0]); 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}.doc"); stream.CopyTo(file); }
Run code

How to generate DOC files in C#

  1. Connect the Wordize SDK to your .NET project
  2. Read the data file, deserialize it into DataTable and call Execute(), specifying the DOC template, output file, save format and data source
  3. Get the generated DOC documents
5%