-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (62 loc) · 3.38 KB
/
Program.cs
File metadata and controls
68 lines (62 loc) · 3.38 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
using DevExpress.Spreadsheet;
using System;
namespace MailMergeExample {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
#region #main
using (Workbook workbook = new Workbook())
{
workbook.Unit = DevExpress.Office.DocumentUnit.Inch;
// Create a mail merge template.
Worksheet template = workbook.Worksheets[0];
template.Rows[1].RowHeight = 1.5;
template.Columns[1].ColumnWidth = 1.0;
template.Columns[1].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
template.Columns[2].ColumnWidth = 2.5;
template.Columns[2].Alignment.WrapText = true;
workbook.BeginUpdate();
template.Cells["C2"].Formula = "FIELDPICTURE(\"Photo\", \"range\", C2, FALSE, 50)";
template.Cells["C3"].Formula = "=FIELD(\"FirstName\")&\" \"&FIELD(\"LastName\")";
template.Cells["B4"].Value = "Position:";
template.Cells["C4"].Formula = "FIELD(\"Title\")";
template.Cells["B5"].Value = "Birth Date:";
template.Cells["C5"].Formula = "FIELD(\"BirthDate\")";
template.Cells["C5"].NumberFormat = "M/d/yyyy";
template.Cells["B6"].Value = "Hire Date:";
template.Cells["C6"].Formula = "FIELD(\"HireDate\")";
template.Cells["C6"].NumberFormat = "dddd MMMM dd, yyyy";
template.Cells["B7"].Value = "Home Phone:";
template.Cells["C7"].Formula = "FIELD(\"HomePhone\")";
template.Cells["B8"].Value = "Address:";
template.Cells["C8"].Formula = "=FIELD(\"Address\")&\" \"&FIELD(\"City\")";
template.Cells["B9"].Value = "About:";
template.Cells["C9"].Formula = "FIELD(\"Notes\")";
workbook.EndUpdate();
// Set a detail range in the template.
CellRange detail = template.Range["C1:C9"];
detail.Name = "DETAILRANGE";
// Set a header range in the template.
CellRange header = template.Range["B1:B9"];
header.Name = "HEADERRANGE";
// Switch the mail merge mode to "Multiple Sheets".
workbook.DefinedNames.Add("MAILMERGEMODE", "=\"Worksheets\"");
// Switch the mail merge mode to "Multiple Documents".
//workbook.DefinedNames.GetDefinedName("MAILMERGEMODE").RefersTo = "\"Documents\"";
// Switch the mail merge mode to "Single Sheet".
//workbook.DefinedNames.GetDefinedName("MAILMERGEMODE").RefersTo = "\"OneWorksheet\"";
// Set vertical document orientation.
workbook.DefinedNames.Add("HORIZONTALMODE", "=TRUE");
// Perform mail merge.
workbook.MailMergeDataSource = EmployeeInfo.EmployeesInfo.GetData();
var result = workbook.GenerateMailMergeDocuments();
result[0].SaveDocument("result.xlsx");
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("result.xlsx") { UseShellExecute = true });
#endregion #main
}
}
}
}