HTML5 Web Editor - Merging a template

The most typical application for the HTML5 Web editor is creating templates for the Text Control Reporting engine MailMerge Using TX Text Control .NET Server for ASP.NET, you can easily deploy a cross-browser, cross-platform template editor with an MS Word look and feel.

Simply click the button Load template, add some text or fields and start the merge process by clicking Merge template server-side.

Demo


Thanks to the flexibility of Text Control's reporting components, you can control the merge process and the resulting document. Using a temporary ServerTextControl instance, you can manipulate the document programmatically in post-merge processes.

Sources

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace tx_aspnet_samples.HTML5
{
    public partial class template : System.Web.UI.Page
    {
        private TXTextControl.DocumentServer.MailMerge mailMerge1;
        private TXTextControl.ServerTextControl serverTextControl1;
        private System.ComponentModel.IContainer components;

        protected void Button2_Click(object sender, EventArgs e)
        {
            // load template into the Web editor
            TextControl1.LoadText(Server.MapPath("/documents/template_master.docx"), 
                TXTextControl.Web.StreamType.WordprocessingML);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            // load the data source (sample database)
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("/datasource/sample_db.xml"), XmlReadMode.Auto);

            // save the template
            byte[] data;
            TextControl1.SaveText(out data, 
                TXTextControl.Web.BinaryStreamType.InternalUnicodeFormat);

            // load the template into the MailMerge reporting engine
            mailMerge1.LoadTemplateFromMemory(data, 
                TXTextControl.DocumentServer.FileFormat.InternalUnicodeFormat);
            
            // merge the template
            mailMerge1.Merge(ds.Tables["Sales_SalesOrderHeader"]);

            // save the resulting document to a byte array
            mailMerge1.SaveDocumentToMemory(out data, 
                TXTextControl.BinaryStreamType.InternalUnicodeFormat, null);
            
            // load the document back into the Web editor
            TextControl1.LoadText(data, 
                TXTextControl.Web.BinaryStreamType.InternalUnicodeFormat);
        }
    }
}

HTML5 Web editor