I have to fill an excel like this
Where I have merged cells on each row. I'm trying to use loadfromcollection, but it ignores the merged cells and it fills each single row.
Please did you know any quick way to do it?
edit: I think that one way is to implement a custom loadfromcollection where the steps are:
- Iterate collection
- For each object, read properties/fields using reflection
- Iterate cell on each row
- check if range address is in worksheet.mergecells
- fill it with property/field value
But in case of complex worksheet (with some loadfromcollection), I think that this approach could be heavy with a big cost.
edit 2: Add an example: Code like this
public class MyObj
{
public string first {get; set;}
public string second {get; set;}
}
...
List<MyObj> myList = new List<MyObj>() {
new MyObj() {first = "first1", second = "second1"},
new MyObj() {first = "first2", second = "second2"} };
...
ws.Cells["A1"].LoadFromCollection(myList);
In a normal worksheet, loadfromcollection has the following output:

If I merge column A and B after filled, I get this:
In case that my worksheet template is
and then I try to fill it using loadfromcollection I get this result
loadfromcollection ignores merged cell, and fill column A and B, but my expectation is




