I want to convert an ExcelRange
object into a model object
Currently, I have the code to get the range in a row
var row = sheet.Dimension.Start.Row + 1;
var lastCol = sheet.Dimension.End.Column;
var endRow = sheet.Dimension.End.Row;
for (; row <= endRow; row++)
{
var range = sheet.Cells[row, 1, row, lastCol];
// code to add here to convert
}
I don't know how to convert this into c# object. The range.Value has object but I don't know how to convert this to a c# model.
EDIT:
My model look like this:
var contact = new ContactHubSpot
{
Id = contactId,
FirstName = candidate.FirstName,
LastName = candidate.LastName,
Gender = candidate.GenderId.HasValue ? candidate.Gender.Name : null,
BirthDate = candidate.BirthDate.HasValue ? candidate.BirthDate.Value.ToMidnightTimestamp() : (long?)null,
Phone = candidate.MobileInternational,
Email = string.IsNullOrEmpty(candidate.EmailAddress) ? null : candidate.EmailAddress,
Bio = candidate.Bio,
IsEmployed = candidate.IsCurrentlyEmployed,
IsOpenToOffers = candidate.IsOpenToOffers,
NoticePeriod = candidate.IsCurrentlyEmployed ? $"{candidate.NoticePeriod} {candidate.NoticePeriodTimeframe.Name}" : string.Empty,
IsLookingForEmployment = candidate.IsLookingForEmployment,
IsLookingForFreelance = candidate.IsLookingForFreelance,
DrivingLicense = candidate.DrivingLicenseId.HasValue ? candidate.DrivingLicense.Name : string.Empty,
ExperienceLevel = candidate.ExperienceLevelId.HasValue ? candidate.ExperienceLevel.Name : string.Empty,
IsCandidate = true,
IsEmployer = false
};