-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
124 lines (104 loc) · 4.21 KB
/
Form1.cs
File metadata and controls
124 lines (104 loc) · 4.21 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using tx_mailmerge_excel.Properties;
using TXTextControl.Windows.Forms.Ribbon;
using static TXTextControl.Windows.Forms.ResourceProvider;
namespace tx_mailmerge_excel
{
public partial class Form1 : TXTextControl.Windows.Forms.Ribbon.RibbonForm
{
Report report;
public Form1()
{
InitializeComponent();
}
public class Report
{
public string Name { get; set; }
}
private void MailMerge_IncludeTextMerging(object sender,
TXTextControl.DocumentServer.MailMerge.IncludeTextMergingEventArgs e)
{
// custom handing of XLSX files
switch (Path.GetExtension(e.IncludeTextField.Filename))
{
case ".xlsx": // Excel file detected
if (!File.Exists(e.IncludeTextField.Filename))
return;
// load document into temp. ServerTextControl
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
{
tx.Create();
// Bookmark name is the sheet name of the Excel document
TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings()
{
DocumentPartName = e.IncludeTextField.Bookmark
};
try
{
// load the Excel document
tx.Load(
e.IncludeTextField.Filename,
TXTextControl.StreamType.SpreadsheetML,
ls);
}
catch {
return;
}
byte[] data;
// save the document using the TX format
tx.Save(out data,
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
e.IncludeTextDocument = data; // pass back to the field
}
break;
}
}
private void Form1_Load(object sender, EventArgs e)
{
// new ribbon group
TXTextControl.Windows.Forms.Ribbon.RibbonGroup rgPreview =
new TXTextControl.Windows.Forms.Ribbon.RibbonGroup();
rgPreview.SmallIcon = Resources.Preview16;
rgPreview.LargeIcon = Resources.Preview32;
rgPreview.Text = "Preview Merge";
rgPreview.DialogBoxLauncher.Visible = false;
rgPreview.HorizontalContentAlignment = TXTextControl.HorizontalAlignment.Center;
// new ribbon button
RibbonButton rbPreview = new RibbonButton();
rbPreview.Text = "Preview";
rbPreview.LargeIcon = Resources.Preview32;
rbPreview.SmallIcon = Resources.Preview16;
rbPreview.Click += RbPreview_Click;
// add button to new gruop
rgPreview.RibbonItems.Add(rbPreview);
// add group to reporting tab
ribbonReportingTab1.RibbonGroups.Insert(0, rgPreview);
// create a sample data source object
report = new Report() { Name = "Test Report" };
ribbonReportingTab1.DataSourceManager.LoadSingleObject(report);
}
private void RbPreview_Click(object sender, EventArgs e)
{
// create a MailMerge instance
TXTextControl.DocumentServer.MailMerge mailMerge =
new TXTextControl.DocumentServer.MailMerge()
{
TextComponent = textControl1
};
// attach the IncludeTextMerging event
mailMerge.IncludeTextMerging += MailMerge_IncludeTextMerging;
// merge template with dummy data
mailMerge.MergeObject(report);
}
}
}