-
Notifications
You must be signed in to change notification settings - Fork 2
/
Form1.vb
210 lines (187 loc) · 14.1 KB
/
Form1.vb
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Imports System
Imports System.Windows.Forms
Imports System.IO
Imports System.Diagnostics
Imports DevExpress.Export.Xl
Namespace XLExportExamples
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
InitTreeListControl()
End Sub
Private Sub InitTreeListControl()
Dim examples As New GroupsOfSpreadsheetExamples()
InitData(examples)
DataBinding(examples)
End Sub
Private Sub InitData(ByVal examples As GroupsOfSpreadsheetExamples)
' #Region "GroupNodes"
examples.Add(New SpreadsheetNode("Basic Actions"))
examples.Add(New SpreadsheetNode("Cell Formatting"))
examples.Add(New SpreadsheetNode("Conditional Formatting"))
examples.Add(New SpreadsheetNode("Data Actions"))
examples.Add(New SpreadsheetNode("Formula Actions"))
examples.Add(New SpreadsheetNode("Page View and Layout"))
examples.Add(New SpreadsheetNode("Pictures"))
examples.Add(New SpreadsheetNode("Sparklines"))
examples.Add(New SpreadsheetNode("Miscellaneous"))
examples.Add(New SpreadsheetNode("Tables"))
' #End Region
' #Region "ExampleNodes"
' Add nodes to the "Basic Actions" group of examples.
examples(0).Groups.Add(New SpreadsheetExample("Create Document", GeneralActions.CreateDocumentAction))
examples(0).Groups.Add(New SpreadsheetExample("Encrypt Document", GeneralActions.EncryptDocumentAction))
examples(0).Groups.Add(New SpreadsheetExample("Create Worksheet", GeneralActions.CreateSheetAction))
examples(0).Groups.Add(New SpreadsheetExample("Hide Worksheet", GeneralActions.CreateHiddenSheetAction))
examples(0).Groups.Add(New SpreadsheetExample("Hide Gridlines", GeneralActions.HideGridlinesAction))
examples(0).Groups.Add(New SpreadsheetExample("Hide Row and Column Headers", GeneralActions.HideHeadersAction))
examples(0).Groups.Add(New SpreadsheetExample("Create Columns", GeneralActions.CreateColumnsAction))
examples(0).Groups.Add(New SpreadsheetExample("Create Rows", GeneralActions.CreateRowsAction))
examples(0).Groups.Add(New SpreadsheetExample("Create Cells", GeneralActions.CreateCellsAction))
examples(0).Groups.Add(New SpreadsheetExample("Merge Cells", GeneralActions.MergeCellsAction))
' Add nodes to the "Cell Formatting" group of examples.
examples(1).Groups.Add(New SpreadsheetExample("Predefined Style-Like Formatting", CellFormattingActions.PredefinedFormattingAction))
examples(1).Groups.Add(New SpreadsheetExample("Themed Formatting", CellFormattingActions.ThemedFormattingAction))
examples(1).Groups.Add(New SpreadsheetExample("Alignment", CellFormattingActions.AlignmentAction))
examples(1).Groups.Add(New SpreadsheetExample("Borders", CellFormattingActions.BordersAction))
examples(1).Groups.Add(New SpreadsheetExample("Fill", CellFormattingActions.FillAction))
examples(1).Groups.Add(New SpreadsheetExample("Font", CellFormattingActions.FontAction))
examples(1).Groups.Add(New SpreadsheetExample("Number Format", CellFormattingActions.NumberFormatAction))
examples(1).Groups.Add(New SpreadsheetExample("Rich Text Formatting", CellFormattingActions.RichTextFormattingAction))
' Add nodes to the "Conditional Formatting" group of examples.
examples(2).Groups.Add(New SpreadsheetExample("Less Than/Greater Than/Between Rules", ConditionalFormattingActions.CellIsAction))
examples(2).Groups.Add(New SpreadsheetExample("Text that Contains... Rule", ConditionalFormattingActions.SpecificTextAction))
examples(2).Groups.Add(New SpreadsheetExample("A Date Occurring... Rule", ConditionalFormattingActions.TimePeriodAction))
examples(2).Groups.Add(New SpreadsheetExample("Duplicate Values", ConditionalFormattingActions.DuplicatesAction))
examples(2).Groups.Add(New SpreadsheetExample("Blank/Non-Blank Cells", ConditionalFormattingActions.BlanksAction))
examples(2).Groups.Add(New SpreadsheetExample("Formula-Based Rules", ConditionalFormattingActions.ExpressionAction))
examples(2).Groups.Add(New SpreadsheetExample("Top/Bottom Rules", ConditionalFormattingActions.Top10Action))
examples(2).Groups.Add(New SpreadsheetExample("Above/Below Average Rules", ConditionalFormattingActions.AverageAction))
examples(2).Groups.Add(New SpreadsheetExample("Color Scales", ConditionalFormattingActions.ColorScaleAction))
examples(2).Groups.Add(New SpreadsheetExample("Data Bars", ConditionalFormattingActions.DataBarAction))
examples(2).Groups.Add(New SpreadsheetExample("Icon Sets", ConditionalFormattingActions.IconSetAction))
' Add nodes to the "Data Actions" group of examples.
examples(3).Groups.Add(New SpreadsheetExample("Enable Filtering", DataActions.AutoFilterAction))
examples(3).Groups.Add(New SpreadsheetExample("Custom Number Filter", DataActions.CustomFilterAction))
examples(3).Groups.Add(New SpreadsheetExample("Filter by Values", DataActions.ValuesFilterAction))
examples(3).Groups.Add(New SpreadsheetExample("Filter by Dates", DataActions.DateFilterAction))
examples(3).Groups.Add(New SpreadsheetExample("Dynamic Filter", DataActions.DynamicFilterAction))
examples(3).Groups.Add(New SpreadsheetExample("Top 10 Filter", DataActions.Top10FilterAction))
examples(3).Groups.Add(New SpreadsheetExample("Filter by Color", DataActions.ColorFilterAction))
examples(3).Groups.Add(New SpreadsheetExample("Outline Data", DataActions.OutlineGroupingAction))
examples(3).Groups.Add(New SpreadsheetExample("Data Validation", DataActions.DataValidationAction))
' Add nodes to the "Formula Actions" group of examples.
examples(4).Groups.Add(New SpreadsheetExample("Simple Formulas", FormulaActions.SimpleFormulasAction))
examples(4).Groups.Add(New SpreadsheetExample("Complex Formulas", FormulaActions.ComplexFormulasAction))
examples(4).Groups.Add(New SpreadsheetExample("Shared Formulas", FormulaActions.SharedFormulasAction))
examples(4).Groups.Add(New SpreadsheetExample("Subtotals", FormulaActions.SubtotalsAction))
' Add nodes to the "Page View and Layout" group of examples.
examples(5).Groups.Add(New SpreadsheetExample("Freeze Row", PageViewAndLayoutActions.FreezeRowAction))
examples(5).Groups.Add(New SpreadsheetExample("Freeze Column", PageViewAndLayoutActions.FreezeColumnAction))
examples(5).Groups.Add(New SpreadsheetExample("Freeze Panes", PageViewAndLayoutActions.FreezePanesAction))
examples(5).Groups.Add(New SpreadsheetExample("Right-To-Left View", PageViewAndLayoutActions.SheetViewRTLAction))
examples(5).Groups.Add(New SpreadsheetExample("Headers and Footers", PageViewAndLayoutActions.HeadersFootersAction))
examples(5).Groups.Add(New SpreadsheetExample("Page Breaks", PageViewAndLayoutActions.PageBreaksAction))
examples(5).Groups.Add(New SpreadsheetExample("Page Margins", PageViewAndLayoutActions.PageMarginsAction))
examples(5).Groups.Add(New SpreadsheetExample("Page Setup", PageViewAndLayoutActions.PageSetupAction))
examples(5).Groups.Add(New SpreadsheetExample("Print Area", PageViewAndLayoutActions.PrintAreaAction))
examples(5).Groups.Add(New SpreadsheetExample("Print Options", PageViewAndLayoutActions.PrintOptionsAction))
examples(5).Groups.Add(New SpreadsheetExample("Print Titles", PageViewAndLayoutActions.PrintTitlesAction))
' Add nodes to the "Pictures" group of examples.
examples(6).Groups.Add(New SpreadsheetExample("Insert Picture", PictureActions.InsertPictureAction))
examples(6).Groups.Add(New SpreadsheetExample("Stretch Picture", PictureActions.StretchPictureAction))
examples(6).Groups.Add(New SpreadsheetExample("Fit Picture in Cell", PictureActions.FitPictureAction))
examples(6).Groups.Add(New SpreadsheetExample("Picture Hyperlink", PictureActions.PictureHyperlinkClickAction))
' Add nodes to the "Sparklines" group of examples.
examples(7).Groups.Add(New SpreadsheetExample("Add Sparkline Group", SparklineActions.AddSparklineGroupAction))
examples(7).Groups.Add(New SpreadsheetExample("Add Sparkline to Group", SparklineActions.AddSparklineAction))
examples(7).Groups.Add(New SpreadsheetExample("Adjust Scaling", SparklineActions.AdjustScalingAction))
examples(7).Groups.Add(New SpreadsheetExample("Highlight Values", SparklineActions.HighlightValuesAction))
examples(7).Groups.Add(New SpreadsheetExample("Display X-axis", SparklineActions.DisplayXAxisAction))
examples(7).Groups.Add(New SpreadsheetExample("Set Date Range", SparklineActions.SetDateRangeAction))
' Add nodes to the "Miscellaneous" group of examples.
examples(8).Groups.Add(New SpreadsheetExample("Insert Hyperlinks", MiscellaneousActions.HyperlinksAction))
examples(8).Groups.Add(New SpreadsheetExample("Document Properties", MiscellaneousActions.DocumentPropertiesAction))
examples(8).Groups.Add(New SpreadsheetExample("Document Options and Restrictions", MiscellaneousActions.DocumentOptionsAction))
examples(8).Groups.Add(New SpreadsheetExample("CSV Export Options", MiscellaneousActions.CsvExportOptionsAction))
' Add nodes to the "Tables" group of examples.
examples(9).Groups.Add(New SpreadsheetExample("Create Table", TableActions.AddTableAction))
examples(9).Groups.Add(New SpreadsheetExample("Disable Filtering", TableActions.DisableFilteringAction))
examples(9).Groups.Add(New SpreadsheetExample("Hidden Header Row", TableActions.HiddenHeaderRowAction))
examples(9).Groups.Add(New SpreadsheetExample("Hidden Total Row", TableActions.HiddenTotalRowAction))
examples(9).Groups.Add(New SpreadsheetExample("Side-By-Side Tables", TableActions.SideBySideAction))
examples(9).Groups.Add(New SpreadsheetExample("Table Style", TableActions.TableStyleAction))
examples(9).Groups.Add(New SpreadsheetExample("Table Style Options", TableActions.TableStyleOptionsAction))
examples(9).Groups.Add(New SpreadsheetExample("Custom Formatting", TableActions.CustomFormattingAction))
examples(9).Groups.Add(New SpreadsheetExample("Calculated Column", TableActions.CalculatedColumnAction))
' #End Region
End Sub
Private Sub DataBinding(ByVal examples As GroupsOfSpreadsheetExamples)
treeList1.DataSource = examples
treeList1.ExpandAll()
treeList1.BestFitColumns()
End Sub
Private Sub RunExample(ByVal filePath As String, ByVal documentFormat As XlDocumentFormat)
Dim example As SpreadsheetExample = TryCast(treeList1.GetDataRecordByNode(treeList1.FocusedNode), SpreadsheetExample)
If example Is Nothing Then
Return
End If
Using stream As New FileStream(filePath, FileMode.Create)
Dim action As Action(Of Stream, XlDocumentFormat) = example.Action
action(stream, documentFormat)
End Using
Process.Start(filePath)
End Sub
Private Sub btnExportToXLSX_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExportToXLSX.Click
If treeList1.FocusedNode Is Nothing Then
Return
End If
Dim fileName As String = GetSaveFileName("Excel Workbook files(*.xlsx)|*.xlsx", "Document.xlsx")
If String.IsNullOrEmpty(fileName) Then
Return
End If
RunExample(fileName, XlDocumentFormat.Xlsx)
End Sub
Private Sub btnExportToXLS_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExportToXLS.Click
If treeList1.FocusedNode Is Nothing Then
Return
End If
Dim fileName As String = GetSaveFileName("Excel 97-2003 Workbook files(*.xls)|*.xls", "Document.xls")
If String.IsNullOrEmpty(fileName) Then
Return
End If
RunExample(fileName, XlDocumentFormat.Xls)
End Sub
Private Sub btnExportToCSV_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExportToCSV.Click
If treeList1.FocusedNode Is Nothing Then
Return
End If
Dim fileName As String = GetSaveFileName("CSV (Comma delimited files)(*.csv)|*.csv", "Document.csv")
If String.IsNullOrEmpty(fileName) Then
Return
End If
RunExample(fileName, XlDocumentFormat.Csv)
End Sub
Private Function GetSaveFileName(ByVal filter As String, ByVal defaulName As String) As String
Dim sfDialog As New SaveFileDialog()
sfDialog.Filter = filter
sfDialog.FileName = defaulName
If sfDialog.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
Return Nothing
End If
Return sfDialog.FileName
End Function
Private Sub EnableButtons(ByVal exampleName As String)
btnExportToCSV.Enabled = Not XLExportDisabledCSVExamples.Examples.Contains(exampleName)
btnExportToXLS.Enabled = Not XLExportForbiddenXLSExamples.Examples.Contains(exampleName)
End Sub
Private Sub treeList1_FocusedNodeChanged(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.FocusedNodeChangedEventArgs) Handles treeList1.FocusedNodeChanged
Dim example As SpreadsheetExample = TryCast(treeList1.GetDataRecordByNode(treeList1.FocusedNode), SpreadsheetExample)
If example Is Nothing Then
Return
End If
EnableButtons(example.Name)
End Sub
End Class
End Namespace