Excel Reports
GenerateFromClassList<T>(IEnumerable<T>,String,String) Method
Example 



KellermanSoftware.ExcelReports Namespace > ExcelReportsGenerator Class > GenerateFromClassList Method : GenerateFromClassList<T>(IEnumerable<T>,String,String) Method
The type of the class
A list of objects of the class
The name for the tab of the worksheet
Where to save the .xlsx file
Creates an Excel file based on the properties of the passed in object. Supports all value types plus reference types of string and DateTime. By default, puts in a header with the names of the properties.
Syntax
Public Overloads Sub GenerateFromClassList(Of T As Class)( _
   ByVal list As IEnumerable(Of T), _
   ByVal worksheetName As String, _
   ByVal filePath As String _
) 
Dim instance As ExcelReportsGenerator
Dim list As IEnumerable(Of T)
Dim worksheetName As String
Dim filePath As String
 
instance.GenerateFromClassList(Of T)(list, worksheetName, filePath)
public void GenerateFromClassList<T>( 
   IEnumerable<T> list,
   string worksheetName,
   string filePath
)
where T: class
public:
void GenerateFromClassListgeneric<typename T>
( 
   IEnumerable<T^>^ list,
   String^ worksheetName,
   String^ filePath
) 
where T: ref class

Parameters

list
A list of objects of the class
worksheetName
The name for the tab of the worksheet
filePath
Where to save the .xlsx file

Type Parameters

T
The type of the class
Example
ExcelReportsGenerator generator = new ExcelReportsGenerator(); //Trial Mode
//ExcelReportsGenerator generator = new ExcelReportsGenerator("place user name here", "place license key here"); //License Mode
 
List<Employee> employees = new List<Employee>();
 
Employee employee1 = new Employee();
employee1.FirstName = "John";
employee1.LastName = "Smith";
employee1.Married = true;
employee1.NumberOfChildren = 3;
employee1.Salary = 60000;
employee1.HealthSavingsContribution = 6250;
employee1.EmployeeType = EmployeeType.LeadAccountant;
employee1.RetirementContributionPercent = .06F;
employee1.YearsOfService = 4;
employee1.QuarterlyMeetingAttendance = 15;
employee1.CompanyCarMileage = 152000;
employee1.VacationHours = 120;
employee1.SickHours = 40;
employee1.PersonalHours = 8;
employee1.BirthDate = new DateTime(1977,12,15);
employees.Add(employee1);
 
Employee employee2 = new Employee();
employee2.FirstName = "Joe";
employee2.LastName = "Jones";
employee2.Married = false;
employee2.NumberOfChildren = 0;
employee2.Salary = 30000;
employee2.HealthSavingsContribution = 3000;
employee2.EmployeeType = EmployeeType.MediumJanitor;
employee2.RetirementContributionPercent = .03F;
employee2.YearsOfService = 1;
employee2.QuarterlyMeetingAttendance = 4;
employee2.CompanyCarMileage = 0;
employee2.VacationHours = 80;
employee2.SickHours = 20;
employee2.PersonalHours = 8;
employee2.BirthDate = new DateTime(1988, 6, 25);
employees.Add(employee2);
 
generator.GenerateFromClassList(employees, "Employees", "GenerateFromListExample.xlsx");
Dim generator As New ExcelReportsGenerator() 'Trial Mode
'Dim generator As New ExcelReportsGenerator("place user name here", "place license key here") 'License Mode
 
Dim employees As New List(Of Employee)()
 
Dim employee1 As New Employee()
employee1.FirstName = "John"
employee1.LastName = "Smith"
employee1.Married = True
employee1.NumberOfChildren = 3
employee1.Salary = 60000
employee1.HealthSavingsContribution = 6250
employee1.EmployeeType = EmployeeType.LeadAccountant
employee1.RetirementContributionPercent =.06F
employee1.YearsOfService = 4
employee1.QuarterlyMeetingAttendance = 15
employee1.CompanyCarMileage = 152000
employee1.VacationHours = 120
employee1.SickHours = 40
employee1.PersonalHours = 8
employee1.BirthDate = New Date(1977,12,15)
employees.Add(employee1)
 
Dim employee2 As New Employee()
employee2.FirstName = "Joe"
employee2.LastName = "Jones"
employee2.Married = False
employee2.NumberOfChildren = 0
employee2.Salary = 30000
employee2.HealthSavingsContribution = 3000
employee2.EmployeeType = EmployeeType.MediumJanitor
employee2.RetirementContributionPercent =.03F
employee2.YearsOfService = 1
employee2.QuarterlyMeetingAttendance = 4
employee2.CompanyCarMileage = 0
employee2.VacationHours = 80
employee2.SickHours = 20
employee2.PersonalHours = 8
employee2.BirthDate = New Date(1988, 6, 25)
employees.Add(employee2)
 
generator.GenerateFromClassList(employees, "Employees", "GenerateFromListExample.xlsx")
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ExcelReportsGenerator Class
ExcelReportsGenerator Members
Overload List