Last active
May 5, 2022 14:37
-
-
Save bjoerntx/22b439a6645f83301c5df9f722a13289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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