-
Notifications
You must be signed in to change notification settings - Fork 37
/
Sample_Main.cs
295 lines (255 loc) · 14.9 KB
/
Sample_Main.cs
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*************************************************************************************************
Required Notice: Copyright (C) EPPlus Software AB.
This software is licensed under PolyForm Noncommercial License 1.0.0
and may only be used for noncommercial purposes
https://polyformproject.org/licenses/noncommercial/1.0.0/
A commercial license to use this software can be purchased at https://epplussoftware.com
*************************************************************************************************
Date Author Change
*************************************************************************************************
01/27/2020 EPPlus Software AB Initial release EPPlus 5
*************************************************************************************************/
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using EPPlusSampleApp.Core;
using EPPlusSamples.CreateFileSystemReport;
using EPPlusSamples.DataValidation;
using EPPlusSamples.EncryptionAndProtection;
using EPPlusSamples.FormulaCalculation;
using EPPlusSamples.FXReportFromDatabase;
using EPPlusSamples.LoadDataFromCsvFilesIntoTables;
using EPPlusSamples.OpenWorkbookAddDataAndChart;
using EPPlusSamples.PerformanceAndProtection;
using EPPlusSamples.PivotTables;
using EPPlusSamples.SalesReport;
using EPPlusSamples.Sparklines;
using EPPlusSamples.Comments;
using EPPlusSamples.LoadingData;
namespace EPPlusSamples
{
class Sample_Main
{
static async Task Main(string[] args)
{
try
{
//EPPlus 5 uses a dual licens model. This requires you to specifiy the License you are using to be able to use the library.
//This sample sets the LicenseContext in the appsettings.json file. An alternative is the commented row below.
//ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
//See https://epplussoftware.com/Developers/LicenseException for more info.
CultureInfo.CurrentCulture = new CultureInfo("zh-tw");
string connectionStr = "Data Source=EPPlusSample.sqlite;Version=3;";
//Set the output directory to the SampleApp folder where the app is running from.
FileUtil.OutputDir = new DirectoryInfo($"{AppDomain.CurrentDomain.BaseDirectory}SampleApp");
// Sample 1 - simply creates a new workbook from scratch
// containing a worksheet that adds a few numbers together
Console.WriteLine("Running sample 1");
string sample1Path = GettingStartedSample.Run();
Console.WriteLine("Sample 1 created: {0}", sample1Path);
Console.WriteLine();
// Sample 2 - simply reads some values from the file generated by sample 1
// and outputs them to the console
Console.WriteLine("Running sample 2");
ReadWorkbookSample.Run();
Console.WriteLine();
//Sample 3 - Load and save using async methods
Console.WriteLine("Running sample 3-Async-Await");
await UsingAsyncAwaitSample.RunAsync(connectionStr);
Console.WriteLine("Sample 3 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 4 - Shows a few ways to load data (Datatable, IEnumerable and more).
Console.WriteLine("Running sample 4");
LoadingDataWithTablesSample.Run();
Console.WriteLine("Sample 4 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 5 Loads two csv files into tables and creates an area chart and a Column/Line chart on the data.
//This sample also shows how to use a secondary axis.
Console.WriteLine("Running sample 5");
var output = await ImportAndExportCsvFilesSample.Run();
Console.WriteLine("Sample 5 created: {0}", output);
Console.WriteLine();
//Sample 6 Calculate - Shows how to calculate formulas in the workbook.
Console.WriteLine("Sample 6 - Calculate formulas");
CalculateFormulasSample.Run();
Console.WriteLine("Sample 6 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 7
//Open sample 1 and add a pie chart.
Console.WriteLine("Running sample 7 - Open a workbook and add data and a pie chart");
output = OpenWorkbookAndAddDataAndChartSample.Run();
Console.WriteLine("Sample 7 created:", output);
Console.WriteLine();
// Sample 8 - creates a workbook from scratch
//Shows how to use Ranges, Styling, Namedstyles and Hyperlinks
Console.WriteLine("Running sample 8");
output = SalesReportFromDatabase.Run(connectionStr);
Console.WriteLine("Sample 8 created: {0}", output);
Console.WriteLine();
//Sample 9
//This sample shows the performance capabilities of the component and shows sheet protection.
//Load X(param 2) rows with five columns
Console.WriteLine("Running sample 9");
output = PerformanceAndProtectionSample.Run(65534);
Console.WriteLine("Sample 9 created:", output);
Console.WriteLine();
//Sample 10 - Linq
//Opens Sample 9 and perform some Linq queries
Console.WriteLine("Running sample 10-Linq");
ReadDataUsingLinq.Run();
Console.WriteLine();
//Sample 11 - Conditional Formatting
Console.WriteLine("Running sample 11");
ConditionalFormatting.Run();
Console.WriteLine("Sample 11 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 12 - Data validation
Console.WriteLine("Running sample 12");
output = DataValidationSample.Run();
Console.WriteLine("Sample 12 created {0}", output);
Console.WriteLine();
//Sample 13 - Filter
Console.WriteLine("Running sample 13-Filter");
await Filter.RunAsync(connectionStr);
Console.WriteLine("Sample 13 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 14 - Shapes & Images
Console.WriteLine("Running sample 14-Shapes & Images");
ShapesAndImagesSample.Run();
Console.WriteLine("Sample 14 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 15 - Themes and Chart styling
Console.WriteLine("Running sample 15-Theme and Chart styling");
//Run the sample with the default office theme
await ChartsAndThemesSample.RunAsync(connectionStr,
FileUtil.GetFileInfo("15-ChartsAndThemes.xlsx"), null);
//Run the sample with the integral theme. Themes can be exported as thmx files from Excel and can then be applied to a package.
await ChartsAndThemesSample.RunAsync(connectionStr,
FileUtil.GetFileInfo("15-ChartsAndThemes-IntegralTheme.xlsx"),
FileUtil.GetFileInfo("15-ChartsAndThemes", "integral.thmx"));
Console.WriteLine("Sample 15 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 16 - Shows how to add sparkline charts.
Console.WriteLine("Running sample 16-Sparklines");
SparkLinesSample.Run();
Console.WriteLine("Sample 16 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
// Sample 17 - Creates a workbook based on a template.
// Populates a range with data and set the series of a linechart.
Console.WriteLine("Running sample 17");
output = FxReportFromDatabase.Run(connectionStr);
Console.WriteLine("Sample 17 created: {0}", output);
Console.WriteLine();
//Sample 18 - Pivottables
//This sample demonstrates how to create and work with pivot tables.
output = PivotTablesSample.Run(connectionStr);
//The second class demonstrates how to style you pivot table.
PivotTablesStylingSample.Run();
Console.WriteLine("Sample 18 created {0}", output);
Console.WriteLine();
//Sample 19 Swedish Quiz : Shows Encryption, workbook- and worksheet protection.
Console.WriteLine("Running sample 19");
DrawingsSample.Run();
Console.WriteLine("Sample 19 created: {0}", FileUtil.OutputDir.FullName);
Console.WriteLine();
//Sample 20
//Creates an advanced report on a directory in the filesystem.
//Parameter 2 is the directory to report. Parameter 3 is how deep the scan will go. Parameter 4 Skips Icons if set to true (The icon handling is slow)
//This example demonstrates how to use outlines, tables,comments, shapes, pictures and charts.
Console.WriteLine("Running sample 20");
output = CreateAFileSystemReport.Run(new DirectoryInfo(System.Reflection.Assembly.GetEntryAssembly().Location).Parent, 5, false);
Console.WriteLine("Sample 20 created:", output);
Console.WriteLine();
//Sample 21 - Shows how to work with macro-enabled workbooks(VBA) and how to sign the code with a certificate.
Console.WriteLine("Running sample 21-VBA");
WorkingWithVbaSample.Run();
SigningYourVBAProject.Run();
Console.WriteLine("Sample 21 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 22 - Ignore cell errors using the IngnoreErrors Collection
Console.WriteLine("Running sample 22-Suppress Errors");
IgnoreErrorsSample.Run();
Console.WriteLine("Sample 22 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 23 - Comments and Threaded comments
Console.WriteLine("Running sample 23-Comments/Notes and Threaded Comments");
CommentsSample.Run();
Console.WriteLine("Sample 23 created {0}", FileUtil.OutputDir.Name);
//Sample 24 - Table slicers and Pivot table slicers
Console.WriteLine("Running sample 24-Table and Pivot table slicers");
SlicerSample.Run(connectionStr);
Console.WriteLine("Sample 23 created {0}", FileUtil.OutputDir.Name);
Console.WriteLine();
//Sample 25 - Import and Export DataTable
Console.WriteLine("Running sample 25 - Import and Export DataTable");
DataTableSample.Run(connectionStr);
Console.WriteLine("Sample 25 finished.");
Console.WriteLine();
//Sample 26 - Form Controls & Drawing Groups
Console.WriteLine("Running sample 26 - Form controls");
FormControlsSample.Run();
Console.WriteLine("Sample 26 finished.");
Console.WriteLine();
//Sample 27 - Custom Named Table, Pivot Table and Slicer styles
Console.WriteLine("Running sample 27 - Custom table and slicer styles");
CustomTableSlicerStyleSample.Run(connectionStr);
Console.WriteLine("Sample 27 finished.");
Console.WriteLine();
//Sample 27 - Custom Named Table, Pivot Table and Slicer styles
Console.WriteLine("Running sample 28 - Working with tables");
await TablesSample.RunAsync(connectionStr);
Console.WriteLine("Sample 28 finished.");
Console.WriteLine();
//Sample 29 - Add references to external workbooks
Console.WriteLine("Running sample 29 - External Links");
ExternalLinksSample.Run();
Console.WriteLine("Sample 29 finished.");
Console.WriteLine();
// Sample 30 - Working with ranges
Console.WriteLine("Running sample 30 - Working with ranges");
CopyRangeSample.Run();
FillRangeSample.Run();
SortingRangesSample.Run();
Console.WriteLine("Sample 30 finished.");
Console.WriteLine();
// Sample 31 - Html Export
//This sample shows basic html export functionality.
//For more advanced samples using charts see https://samples.epplussoftware.com/HtmlExport
Console.WriteLine("Running sample 31 - Html export");
HtmlTableExportSample.Run();
await HtmlRangeExportSample.RunAsync();
Console.WriteLine("Sample 31 finished.");
Console.WriteLine();
//Sample 32 - Json Export
//This sample shows the json export functionality.
//For more a samples exporting to chart librays see https://samples.epplussoftware.com/JsonExport
Console.WriteLine("Running sample 32 - json export");
await JsonExportSample.RunAsync();
Console.WriteLine("Sample 32 finished.");
Console.WriteLine();
// Sample 33 - ToCollection and ToCollectionWithMappings
// This sample shows how to export data from a worksheet
// to a IEnumerable<T> where T is a class.
Console.WriteLine("Running sample 33 - ToCollection and ToCollectionWithMappings");
ToCollectionSample.Run();
Console.WriteLine("Sample 33 finished.");
Console.WriteLine();
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex.Message);
}
var prevColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Genereted sample workbooks can be found in {FileUtil.OutputDir.FullName}");
Console.ForegroundColor = prevColor;
//Open the output folder
Process.Start(FileUtil.OutputDir.FullName);
Console.WriteLine();
Console.WriteLine("Press the return key to exit...");
Console.ReadKey();
}
}
}