Last active
January 27, 2020 10:13
-
-
Save bjoerntx/aaece9139b5679355923670dc8f10445 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
using myFirstAzureWebApp.Models; | |
using System; | |
using System.Data; | |
using System.Web.Mvc; | |
namespace myFirstAzureWebApp.Controllers | |
{ | |
public class HomeController : Controller | |
{ | |
public ActionResult Index() | |
{ | |
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) | |
{ | |
tx.Create(); | |
// load MS Word merge fields and included merge blocks | |
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings() | |
{ | |
ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord, | |
LoadSubTextParts = true | |
}; | |
// load the template | |
tx.Load(Server.MapPath("~/App_Data/invoice.docx"), | |
TXTextControl.StreamType.WordprocessingML, ls); | |
using (TXTextControl.DocumentServer.MailMerge mailMerge = | |
new TXTextControl.DocumentServer.MailMerge()) | |
{ | |
mailMerge.TextComponent = tx; | |
DataSet ds = new DataSet(); | |
ds.ReadXml(Server.MapPath("~/App_Data/sample_db.xml"), XmlReadMode.Auto); | |
// merge data into template | |
mailMerge.Merge(ds.Tables[0]); | |
byte[] data = null; | |
tx.Save(out data, TXTextControl.BinaryStreamType.InternalUnicodeFormat); | |
// return the document and the document name | |
DocumentView documentView = new DocumentView() | |
{ | |
DocumentData = Convert.ToBase64String(data), | |
DocumentName = ls.LoadedFile | |
}; | |
return View(documentView); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment