export to Excel from a list with EPPLUS

Solution 1:

What version of EPPlus are you using? I ask because I am surprised it does not throw an error as it does with 4.1.0 which is currently the latest. Maybe an older version is more forgiving.

But to answer you question, if you look at the signature of the final overload of LoadFromCollection that is eventually called you will see this:

public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection, bool PrintHeaders, TableStyles TableStyle, BindingFlags memberFlags, MemberInfo[] Members)

Notice that Epplus is only looking at MemberInfos and not a Fields which is what you object is using. If you change Stock object to this:

class Stock
{
    public string Nif { get; set; }
    public string Proveedor { get; set; }
    public string Coodigo { get; set; }
    public string descripcion { get; set; }
    public string Catalogo { get; set; }
    public string Estadistico { get; set; }
    public decimal StockOn { get; set; }
}

You should see results.