Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active May 5, 2022 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/22b439a6645f83301c5df9f722a13289 to your computer and use it in GitHub Desktop.
Save bjoerntx/22b439a6645f83301c5df9f722a13289 to your computer and use it in GitHub Desktop.
// enable MS Word merge fields
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings() {
ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord };
// load JSON data
string jsonData = System.IO.File.ReadAllText("data.json");
// create a temporary ServerTextControl
using (TXTextControl.ServerTextControl serverTextControl =
new TXTextControl.ServerTextControl()) {
serverTextControl.Create();
// load the template
serverTextControl.Load("template.docx", TXTextControl.StreamType.WordprocessingML, ls);
// create the mail merge engine
using (MailMerge mailMerge = new MailMerge()) {
// connect to ServerTextControl
mailMerge.TextComponent = serverTextControl;
// merge data into template
mailMerge.MergeJsonData(jsonData);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment