-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.vb
More file actions
68 lines (61 loc) · 2.71 KB
/
Program.vb
File metadata and controls
68 lines (61 loc) · 2.71 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
Imports DevExpress.Spreadsheet
Imports System
Namespace MailMergeExample
Friend Module Program
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread>
Sub Main()
' #Region "#main"
Using workbook As New Workbook()
workbook.Unit = DevExpress.Office.DocumentUnit.Inch
' Create a mail merge template.
Dim template As Worksheet = 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.
Dim detail As CellRange = template.Range("C1:C9")
detail.Name = "DETAILRANGE"
' Set a header range in the template.
Dim header As CellRange = 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()
Dim result = workbook.GenerateMailMergeDocuments()
result(0).SaveDocument("result.xlsx")
System.Diagnostics.Process.Start(New ProcessStartInfo("result.xlsx") With {.UseShellExecute = True})
End Using
' #End Region
End Sub
End Module
End Namespace