Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping of nested objects via column index #276

Open
rmolino opened this issue Sep 7, 2023 · 1 comment
Open

Mapping of nested objects via column index #276

rmolino opened this issue Sep 7, 2023 · 1 comment

Comments

@rmolino
Copy link

rmolino commented Sep 7, 2023

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);

@mganss
Copy link
Owner

mganss commented Sep 7, 2023

This should be possible, see here for an example:

public void NestedProductIndexMappedTest()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants