1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IO ;
3
4
using ICG . NetCore . Utilities . Spreadsheet ;
4
5
using Microsoft . Extensions . DependencyInjection ;
5
6
using NetCore . Utilities . SpreadsheetExample . Models ;
6
7
7
- namespace NetCore . Utilities . SpreadsheetExample
8
+ namespace NetCore . Utilities . SpreadsheetExample ;
9
+
10
+ internal class Program
8
11
{
9
- class Program
12
+ private static void Main ( string [ ] args )
10
13
{
11
- static void Main ( string [ ] args )
14
+ //Setup our DI Container
15
+ var services = new ServiceCollection ( ) ;
16
+ services . UseIcgNetCoreUtilitiesSpreadsheet ( ) ;
17
+ var provider = services . BuildServiceProvider ( ) ;
18
+
19
+ //Get our generator and export
20
+ var exportGenerator = provider . GetRequiredService < ISpreadsheetGenerator > ( ) ;
21
+ var exportDefinition = new SpreadsheetConfiguration < SimpleExportData >
12
22
{
13
- //Setup our DI Container
14
- var services = new ServiceCollection ( ) ;
15
- services . UseIcgNetCoreUtilitiesSpreadsheet ( ) ;
16
- var provider = services . BuildServiceProvider ( ) ;
23
+ RenderTitle = true ,
24
+ DocumentTitle = "Sample Export of 100 Records" ,
25
+ RenderSubTitle = true ,
26
+ DocumentSubTitle = "Showing the full options" ,
27
+ ExportData = GetSampleExportData ( 100 ) ,
28
+ WorksheetName = "Sample" ,
29
+ FreezeHeaders = true ,
30
+ AutoFilterDataRows = true
31
+ } ;
32
+ var fileContent = exportGenerator . CreateSingleSheetSpreadsheet ( exportDefinition ) ;
33
+ File . WriteAllBytes ( "Sample.xlsx" , fileContent ) ;
17
34
18
- //Get our generator and export
19
- var exportGenerator = provider . GetRequiredService < ISpreadsheetGenerator > ( ) ;
20
- var exportDefinition = new SpreadsheetConfiguration < SimpleExportData >
35
+ //Sample 2 sheet export
36
+ var multiSheetDefinition = new MultisheetConfiguration ( )
37
+ . WithSheet ( "Sheet 1" , GetSampleExportData ( 100 ) )
38
+ . WithSheet ( "Additional Sheet" , GetSampleExportData ( 500 ) , config =>
21
39
{
22
- RenderTitle = true ,
23
- DocumentTitle = "Sample Export of 100 Records" ,
24
- RenderSubTitle = true ,
25
- DocumentSubTitle = "Showing the full options" ,
26
- ExportData = GetSampleExportData ( 100 ) ,
27
- WorksheetName = "Sample" ,
28
- FreezeHeaders = true
29
- } ;
30
- var fileContent = exportGenerator . CreateSingleSheetSpreadsheet ( exportDefinition ) ;
31
- System . IO . File . WriteAllBytes ( "Sample.xlsx" , fileContent ) ;
32
-
33
- //Sample 2 sheet export
34
- var multiSheetDefinition = new MultisheetConfiguration ( )
35
- . WithSheet ( "Sheet 1" , GetSampleExportData ( 100 ) )
36
- . WithSheet ( "Additional Sheet" , GetSampleExportData ( 500 ) , config =>
37
- {
38
- config . DocumentTitle = "Lots of data" ;
39
- config . RenderTitle = true ;
40
- config . FreezeHeaders = true ;
41
- } ) ;
40
+ config . DocumentTitle = "Lots of data" ;
41
+ config . RenderTitle = true ;
42
+ config . FreezeHeaders = true ;
43
+ config . AutoFilterDataRows = true ;
44
+ } ) ;
42
45
43
- var multiFileContent = exportGenerator . CreateMultiSheetSpreadsheet ( multiSheetDefinition ) ;
44
- System . IO . File . WriteAllBytes ( "Sample-Multi.xlsx" , multiFileContent ) ;
45
- Console . WriteLine ( "Files Created" ) ;
46
- Console . ReadLine ( ) ;
47
- }
46
+ var multiFileContent = exportGenerator . CreateMultiSheetSpreadsheet ( multiSheetDefinition ) ;
47
+ File . WriteAllBytes ( "Sample-Multi.xlsx" , multiFileContent ) ;
48
+ Console . WriteLine ( "Files Created" ) ;
49
+ Console . ReadLine ( ) ;
50
+ }
48
51
49
- private static List < SimpleExportData > GetSampleExportData ( int numberOfRecords )
50
- {
51
- var listData = new List < SimpleExportData > ( ) ;
52
- for ( var i = 0 ; i < numberOfRecords ; i ++ )
52
+ private static List < SimpleExportData > GetSampleExportData ( int numberOfRecords )
53
+ {
54
+ var listData = new List < SimpleExportData > ( ) ;
55
+ for ( var i = 0 ; i < numberOfRecords ; i ++ )
56
+ listData . Add ( new SimpleExportData
53
57
{
54
- listData . Add ( new SimpleExportData
55
- { DueDate = DateTime . Now . AddDays ( i ) , Notes = $ "Record { i } notes" , TotalCost = 15m , Title = $ "Sample Data Row #{ i } "} ) ;
56
- }
58
+ DueDate = DateTime . Now . AddDays ( i ) , Notes = $ "Record { i } notes" , TotalCost = 15m ,
59
+ TestingNumbers = 1234.4567289m , Title = $ "Sample Data Row #{ i } "
60
+ } ) ;
57
61
58
- return listData ;
59
- }
62
+ return listData ;
60
63
}
61
- }
64
+ }
0 commit comments