-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebForm1.aspx.cs
More file actions
78 lines (65 loc) · 2.66 KB
/
WebForm1.aspx.cs
File metadata and controls
78 lines (65 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 _3e_sample
{
public partial class WebForm1 : System.Web.UI.Page
{
private TXTextControl.DocumentServer.MailMerge mailMerge1;
private System.ComponentModel.IContainer components;
private TXTextControl.ServerTextControl serverTextControl1;
protected void Page_Load(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.serverTextControl1 = new TXTextControl.ServerTextControl();
this.mailMerge1 = new TXTextControl.DocumentServer.MailMerge(this.components);
//
// serverTextControl1
//
this.serverTextControl1.SpellChecker = null;
//
// mailMerge1
//
this.mailMerge1.TextComponent = this.serverTextControl1;
}
protected void Button1_Click(object sender, EventArgs e)
{
// create a new sample data source
DataTable dt = new DataTable();
dt.Columns.Add("company");
dt.Columns.Add("name");
dt.Rows.Add(new string[] { "Text Control", "Peter Jackson" });
dt.Rows.Add(new string[] { "Microsoft", "Sue Williamson" });
dt.Rows.Add(new string[] { "Google", "Peter Gustavsson" });
// load the template
mailMerge1.LoadTemplate(Server.MapPath("template.docx"), TXTextControl.DocumentServer.FileFormat.WordprocessingML);
// attached the DataRowMerged event
mailMerge1.DataRowMerged += mailMerge1_DataRowMerged;
// merge with the appenbd parameter "false"
mailMerge1.Merge(dt, false);
}
void mailMerge1_DataRowMerged(object sender, TXTextControl.DocumentServer.MailMerge.DataRowMergedEventArgs e)
{
string htmlDocument = "";
// load the merged records into a temporary ServerTextControl
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Load(e.MergedRow, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// save the results as HTML
tx.Save(out htmlDocument, TXTextControl.StringStreamType.HTMLFormat);
}
// write the HTML to the browser
Response.Write(htmlDocument);
Response.Write("<hr />");
}
}
}