creating merged cells to display hierarchical data

Sep 9, 2011 at 1:01 PM
Edited Sep 9, 2011 at 1:07 PM

I've followig classes

public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; } 

        private IList<Child> _children;
        public IList<Child> Children
        {
            get;
            set;
        }
    }
    public class Child {
        public string Name { get; set; }
        public int Age { get; set; } 
    }

How can I generate a excel file looks like below? 

Parent Age Child Name Child Age
parent 1 60 Child 1 20
Child 2 18
Parent 2 58 Child 21 15
Child 22 12

i tried following method, but it fails:

List<Person> pp = new List<Person>(); 
//add some persons data in pp here  
excelWorksheet.Cells["A1"].LoadFromCollection<Person>(pp, true);

 

Editor
Sep 9, 2011 at 1:09 PM

You will need to do two for-loop and write each cell manually, it´s very easy. Look at sample´s folder.