Skip to content

Mapping of nested objects via column index #276

@rmolino

Description

@rmolino

Hello,
is it possible to map to objects containing nested objects when performing the mapping via column index?

    public class EroeffnungbilanzWert
    {
        public string Kontonummer { get; set; }
        public WertDaten Wertdaten { get; set; } = new();
    }

    public class WertDaten
    {
        public string Wert { get; set; }
        public string Soll { get; set; }
        public string Haben { get; set; }
    }

By using this code the mapped values are not set to the nested object, but it runs without exception:

            var excelMapper = new ExcelMapper(stream)
            {
                HeaderRow = true,
                MinRowNumber = 2,
                SkipBlankCells = false
            };
            excelMapper.AddMapping<EroeffnungbilanzWert>(5, s => s.Wertdaten.Soll);

This code results in an exception:
var excelMapper = new ExcelMapper(stream)
{
HeaderRow = false,
MinRowNumber = 2,
SkipBlankCells = false
};
excelMapper.AddMapping(4, s => s.Wertdaten.Soll);

image

But this code (not using nested object) works like expected:
var excelMapper = new ExcelMapper(stream)
{
HeaderRow = false,
MinRowNumber = 2,
SkipBlankCells = false
};
excelMapper.AddMapping(1, s => s.Kontonummer);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions