VahidN / EPPlus.Core

EPPlus.Core is an unofficial port of the EPPlus library to .NET Core
GNU Lesser General Public License v3.0
370 stars 93 forks source link

Null reference exception on .GetAsByteArray() #27

Closed GeeWizWow closed 7 years ago

GeeWizWow commented 7 years ago

I've implemented this simple use case and am getting a null reference exception on .GetAsByteArray()

using (var package = new ExcelPackage())
            {
                foreach (var contract in contracts)
                {
                    using (var worksheet = package.Workbook.Worksheets.Add(contract.Value.Name))
                    {
                        var dt = contract.Value.Activities.Select(r => new
                        {
                            r.Name,
                            r.User,
                            r.Status,
                            r.Time
                        })
                        .ToList();

                        worksheet.Cells["A1"].LoadFromCollection(dt);
                    }
                }

                var result = package.GetAsByteArray();

Edit: Exception is being thrown by CellsStoreEnumerator.Init. seems like _cellStore is possibly null?

VahidN commented 7 years ago

Remove the second using statement and it will work (don't dispose an in use worksheet).

GeeWizWow commented 7 years ago

Will give it a go, thanks for your time sir