Skip to content
New issue

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

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

Already on GitHub? # to your account

how to ignore the property if there is no specified column in the file?! I get an exception no read row 0 #83

Closed
Parsifal9209 opened this issue Dec 9, 2022 · 4 comments

Comments

@Parsifal9209
Copy link

Parsifal9209 commented Dec 9, 2022

image
image

Map(bonus => bonus.PartnerFio) .WithColumnNameMatching(x => x == "partner_fio" || x == "fio" || x == "ФИО" || x == "ФИО Клиента") .WithEmptyFallback(null) .WithInvalidFallback(null);

How set default value, if field not mapped

@Parsifal9209
Copy link
Author

I'm sorry to bother you, I seem to have found what I need it is property .MapOptional().
Issue can close

@hughbe hughbe closed this as completed Dec 9, 2022
@anjared
Copy link

anjared commented Sep 21, 2023

I'm adding to this so if others stumble upon this they know the actual property is: MakeOptional(). I found this to work to ignore a property that didn't exist in the file versus using the [ExcelIgnore] attribute on the property.

@arisliang

This comment was marked as resolved.

@arisliang
Copy link

arisliang commented Dec 20, 2023

I find using MakeOptional is not ideal, because it will use custom mapping, and make ExcelColumnName attribute useless, please correct me if I'm wrong.

Ideally, we can still rely on ExcelColumnName as a default behavior, and use ExcelIgnore, so the column can read value if there is such column; and set to null if there is no such column (instead of throwing errors, because it could be legitimate not having a column sometimes).

Assuming two excel files, one with such column, and one without. And the code needs to work with both.

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

No branches or pull requests

4 participants