excel-mapper icon indicating copy to clipboard operation
excel-mapper copied to clipboard

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

Open laventnc opened this issue 4 years ago • 0 comments

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

laventnc avatar Jan 27 '22 21:01 laventnc