Epplus将范围对象转换为c#模型

Epplus将范围对象转换为c#模型,c#,epplus,epplus-4,C#,Epplus,Epplus 4,我想将ExcelRange对象转换为模型对象 目前,我有代码来获取一行中的范围 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];

我想将
ExcelRange
对象转换为模型对象

目前,我有代码来获取一行中的范围

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
}

你能分享你的
模型对象的样子吗?@WSC完成添加模型看起来你基本上就在那里了。您现在需要做的就是创建一个
新的ContactHubSpot
对象,并从
范围
中指定各种属性(从外观上看,这只是一行数据)。大概您知道列的顺序(或者有一些先前的代码按照您的期望格式化数据)。通过执行
range.Item(col,row)
@WSC可以访问
range
中的特定单元格。是的,我知道我可以这样做。但是我想要的是简化所有的事情,比如这个问题,那么你要做什么呢?我不太确定你的问题是什么;你知道你想做什么,你有一种方法,你有一个替代的例子。如果你有问题,你至少需要尝试一个解决方案,然后问一个问题。
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
        };