Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathLoadingDataFromCollectionWithAttributes.cs
More file actions
Latest commit
117 lines (97 loc) · 5.96 KB
/
Copy pathLoadingDataFromCollectionWithAttributes.cs
File metadata and controls
117 lines (97 loc) · 5.96 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
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
usingOfficeOpenXml;
usingOfficeOpenXml.Attributes;
usingOfficeOpenXml.Table;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceEPPlusSamples.LoadingData
{
[EpplusTable(TableStyle=TableStyles.Dark1,PrintHeaders=true,AutofitColumns=true,AutoCalculate=false,ShowTotal=true,ShowFirstColumn=true)]
[
EpplusFormulaTableColumn(Order=6,NumberFormat="€#,##0.00",Header="Tax amount",FormulaR1C1="RC[-2] * RC[-1]",TotalsRowFunction=RowFunctions.Sum,TotalsRowNumberFormat="€#,##0.00"),
EpplusFormulaTableColumn(Order=7,NumberFormat="€#,##0.00",Header="Net salary",Formula="E2-G2",TotalsRowFunction=RowFunctions.Sum,TotalsRowNumberFormat="€#,##0.00")
]
internalclassActor
{
[EpplusIgnore]
publicintId{get;set;}
[EpplusTableColumn(Order=3)]
publicstringLastName{get;set;}
[EpplusTableColumn(Order=1,Header="First name")]
publicstringFirstName{get;set;}
[EpplusTableColumn(Order=2)]
publicstringMiddleName{get;set;}
[EpplusTableColumn(Order=0,NumberFormat="yyyy-MM-dd",TotalsRowLabel="Total")]
publicDateTimeBirthdate{get;set;}
[EpplusTableColumn(Order=4,NumberFormat="€#,##0.00",TotalsRowFunction=RowFunctions.Sum,TotalsRowNumberFormat="€#,##0.00")]
publicdoubleSalary{get;set;}
[EpplusTableColumn(Order=5,NumberFormat="0%",TotalsRowFormula="Table1[[#Totals],[Tax amount]]/Table1[[#Totals],[Salary]]",TotalsRowNumberFormat="0 %")]
publicdoubleTax{get;set;}
}
[EpplusTable(TableStyle=TableStyles.Medium1,PrintHeaders=true,AutofitColumns=true,AutoCalculate=true,ShowLastColumn=true)]
internalclassActor2:Actor
{
}
// classes used to demonstrate this functionality with a complex type property
[EpplusTable(TableStyle=TableStyles.Light14,PrintHeaders=true,AutofitColumns=true,AutoCalculate=true,ShowLastColumn=true)]
internalclassActor3
{
[EpplusIgnore]
publicintId{get;set;}
[EpplusNestedTableColumn(Order=1)]
publicActorNameName{get;set;}
[EpplusTableColumn(Order=0,NumberFormat="yyyy-MM-dd",TotalsRowLabel="Total")]
publicDateTimeBirthdate{get;set;}
[EpplusTableColumn(Order=2,NumberFormat="€#,##0.00",TotalsRowFunction=RowFunctions.Sum,TotalsRowNumberFormat="€#,##0.00")]
publicdoubleSalary{get;set;}
[EpplusTableColumn(Order=3,NumberFormat="0%",TotalsRowFormula="Table1[[#Totals],[Tax amount]]/Table1[[#Totals],[Salary]]",TotalsRowNumberFormat="0 %")]
publicdoubleTax{get;set;}
}
internalclassActorName
{
[EpplusTableColumn(Order=3)]
publicstringLastName{get;set;}
[EpplusTableColumn(Order=1,Header="First name")]
publicstringFirstName{get;set;}
[EpplusTableColumn(Order=2)]
publicstringMiddleName{get;set;}
}
publicstaticclassLoadingDataFromCollectionWithAttributes
{
publicstaticvoidRun()
{
// sample data
varactors=newList<Actor>
{
newActor{Salary=256.24,Tax=0.21,FirstName="John",MiddleName="Bernhard",LastName="Doe",Birthdate=newDateTime(1950,3,15)},
newActor{Salary=278.55,Tax=0.23,FirstName="Sven",MiddleName="Bertil",LastName="Svensson",Birthdate=newDateTime(1962,6,10)},
newActor{Salary=315.34,Tax=0.28,FirstName="Lisa",MiddleName="Maria",LastName="Gonzales",Birthdate=newDateTime(1971,10,2)}
};
varsubclassActors=newList<Actor2>
{
newActor2{Salary=256.24,Tax=0.21,FirstName="John",MiddleName="Bernhard",LastName="Doe",Birthdate=newDateTime(1950,3,15)},
newActor2{Salary=278.55,Tax=0.23,FirstName="Sven",MiddleName="Bertil",LastName="Svensson",Birthdate=newDateTime(1962,6,10)},
newActor2{Salary=315.34,Tax=0.28,FirstName="Lisa",MiddleName="Maria",LastName="Gonzales",Birthdate=newDateTime(1971,10,2)}
};
varcomplexTypeActors=newList<Actor3>
{
newActor3{Salary=256.24,Tax=0.21,Name=newActorName{FirstName="John",MiddleName="Bernhard",LastName="Doe"},Birthdate=newDateTime(1950,3,15)},
newActor3{Salary=278.55,Tax=0.23,Name=newActorName{FirstName="Sven",MiddleName="Bertil",LastName="Svensson"},Birthdate=newDateTime(1962,6,10)},
newActor3{Salary=315.34,Tax=0.28,Name=newActorName{FirstName="Lisa",MiddleName="Maria",LastName="Gonzales"},Birthdate=newDateTime(1971,10,2)}
};
using(varpackage=newExcelPackage(FileUtil.GetCleanFileInfo("04-LoadFromCollectionAttributes.xlsx")))
{
// using the Actor class above
varsheet=package.Workbook.Worksheets.Add("Actors");
sheet.Cells["A1"].LoadFromCollection(actors);
// using a subclass where we have overridden the EpplusTableAttribute (different TableStyle and highlight last column instead of the first).
varsubclassSheet=package.Workbook.Worksheets.Add("Using subclass with attributes");
subclassSheet.Cells["A1"].LoadFromCollection(subclassActors);
// using a subclass where we have overridden the EpplusTableAttribute (different TableStyle and highlight last column instead of the first).
varcomplexTypePropertySheet=package.Workbook.Worksheets.Add("Complex type property");
complexTypePropertySheet.Cells["A1"].LoadFromCollection(complexTypeActors);
package.Save();
}
}
}
}