ExcelMapper icon indicating copy to clipboard operation
ExcelMapper copied to clipboard

please help, cannot mapped group columns

Open JL-Yondu opened this issue 2 years ago • 1 comments

Hi can you help with these one? I cannot mapped the group header columns into my model property. Is there a way to mapped this one? How to get the child within these group/parent: "Insured", "Home Address", "Provincial Address" ?

Please see this screenshot for test data: Screenshot 2023-03-27 214917

JL-Yondu avatar Mar 27 '23 13:03 JL-Yondu

Unfortunately, there is currently no support for multiple nested properties with the same type, e.g. properties HomeAddress and WorkAddress of type Address in the example above. Also, header columns that span multiple rows are unsupported.

The simplest possible workaround that comes to mind is to create an intermediate class that is used just for mapping from Excel, then map the resulting objects to your final desired class hierarchy. For example:

public class CustomerExcel
{
    [Column(Letter = "A")]
    public string PolicyNumber { get; set; }
    [Column(Letter = "B")]
    public DateTime IssueDate { get; set; }
    [Column(Letter = "C")]
    public DateTime EffectiveDate { get; set; }
    // ...
    [Column(Letter = "I")]
    public string HomeHouseNo { get; set; }
    // ...
    [Column(Letter = "M")]
    public string WorkHouseNo { get; set; }
}

mganss avatar Mar 28 '23 11:03 mganss