ExcelMapper icon indicating copy to clipboard operation
ExcelMapper copied to clipboard

Mapping of nested objects via column index

Open rmolino opened this issue 2 years ago • 1 comments

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<EroeffnungbilanzWert>(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<EroeffnungbilanzWert>(1, s => s.Kontonummer);

rmolino avatar Sep 07 '23 11:09 rmolino

This should be possible, see here for an example: https://github.com/mganss/ExcelMapper/blob/10a751f40ef0ad48732bf6995556b31b6aab680d/ExcelMapper.Tests/Tests.cs#L2437

mganss avatar Sep 07 '23 16:09 mganss