0

I want to set each element of collection in one row, but they are always added in one column, not row.

var headers = new List<string> {...};
var row = 4;
worksheet.Cells[row, 2, row, headers.Count()].LoadFromCollection(headers);

From code - I select Range in what I want to load collection. But it doesn't work as expected. Result in image (Dates should be in row as column headers).

generated file

Using EPPlus version 4.5.3.2

demo
  • 6,038
  • 19
  • 75
  • 149

1 Answers1

0

LoadFromCollection is supposed to work like that. Normally you pass it a collection of a complex type, then the properties of that type become the column headers, while each item in the collection is populated on a separate row.

Since you're passing a simple type, it's just like you passed a complex type with a single property. Every value goes on a different row.

If you instead want the items in your collection to be on the same row, just write a for loop to iterate over the items in the collection and add them.

mason
  • 31,774
  • 10
  • 77
  • 121