Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 2262

Commented Unassigned: .LoadFromCollection Throws OutOfRange Exception if collection is empty [14971]

$
0
0
v3.1.3, Beta 4.0, v3.0

Example:
```
using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("EmptyCollectionBug");
List<string> aList = new List<string>();
aList.Add("Test");

ws.Cells["K8"].LoadFromCollection<string>(aList.Where(i => i != "Test"));
}

```

My fix:
ExcelRangeBase.cs, line 2016, Add:
```
if (Collection.Count() < 1)
return null;
```
Likely a better way to do this, but it gets the job done. Obviously code can check for 0 count collections rather than lib, but it saved me writing a lot more code.
Comments: I sent a pull request to fix this with a unit test. It seems to be a more sensible solution in that it will still add headers for an empty collection. I added a unit test too. It passed https://epplus.codeplex.com/SourceControl/network/forks/zippy1981/LoadFromEmptyCollection?branch=default

Viewing all articles
Browse latest Browse all 2262

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>