Perform the following steps:
- Create a class named EPPLusExcelManager and paste the following code. This class has a method named ReadExcelData, which uses a library named EPPlus to read the data from the Excel file (.xlsx extension). It reads each row, creates an Employee object for each row, and then returns an employee collection. We will create the Employee class in a moment:
class EPPLusExcelManager
{
public List<Employee> ReadExcelData(Stream stream)
{
List<Employee> employees = new List<Employee>();
//FileInfo existingFile = new FileInfo("EmployeeInformation.xlsx");
using (ExcelPackage package = new ExcelPackage(stream))
{
ExcelWorksheet ExcelWorksheet = package.Workbook.Worksheets[0];
for (int EmployeeIndex = 2; EmployeeIndex < ExcelWorksheet.Dimension.Rows + 1; EmployeeIndex++)
{
employees.Add(new Employee()
{
EmpId = Convert.ToString(ExcelWorksheet.Cells[EmployeeIndex, 1].Value),
Name = Convert.ToString(ExcelWorksheet.Cells[EmployeeIndex, 2].Value),
Email = Convert.ToString(ExcelWorksheet.Cells[EmployeeIndex, 3].Value),
PhoneNumber = Convert.ToString(ExcelWorksheet.Cells[EmployeeIndex, 4].Value)
});
}
}
return employees;
}
}
- Now, let's create another class named Employee and copy the following code:
public class Employee
{
public string EmpId { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
}
If you build the application now, you should not see any errors. We are done with developing the dependencies for our first activity trigger function. Let's now start building the actual activity trigger.