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

SkipBlankLines not working as expected (empty string vs. null) #78

Open
laventnc opened this issue Jan 27, 2022 · 0 comments
Open

SkipBlankLines not working as expected (empty string vs. null) #78

laventnc opened this issue Jan 27, 2022 · 0 comments

Comments

@laventnc
Copy link

When reading an xlsx file, with cell values as "" (empty), SkipBlankLines fails skip the line (because it checks for null).

Shouldn't an empty cell be treated the same way as null? If there's a specific reason for this, is there anyway to override this logic? I'm thinking of how the base library has the FilterRow setting.

I'll attach an example sheet with some code for quick verification:

using var stream = file.OpenReadStream();
using var importer = new ExcelImporter( stream );
importer.Configuration.SkipBlankLines = true;
importer.Configuration.RegisterClassMap<EventClassMap>();

var sheet = importer.ReadSheet();
var heading = sheet.ReadHeading();

foreach (var evt in sheet.ReadRows<Event>())
{
    // throws error as blank lines aren't skipped & non-nullable fields cannot be mapped to: ""
}

...

public class Event
{
    public string Name { get; set; }
    public string Location { get; set; }
    public int Attendance { get; set; }
    public DateTime Date { get; set; }
}
public class EventClassMap : ExcelClassMap<Event>
{
    public EventClassMap()
    {
        Map( e => e.Date )
            .WithDateFormats( "M/d/yyyy hh:mm:ss tt", "g" );
    }
}

An example sheet can be found here

# 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

1 participant