How to load custom object list to epplus

Nov 27, 2012 at 4:35 PM

I have to make export from list with collapse/expand feature as I have object in object. I don't have luck to implement this here what I have try:

Person p1 = new Person {UserId = 1, FirstName = "John", LastName = "Doe"};
            Person p2 = new Person { UserId = 2, FirstName = "Super", LastName = "Man" };
            Address a1 = new Address {AddressId = 56, City = "Washington", Title = "Some Address"};
            p1.Address = a1;
            p2.Address = a1;

            List people = new List();
            people.Add(p1);
            people.Add(p2);

string excelSheetName = "test";

            string fileName = "ByteOfCode";
            string currentDirectorypath = Environment.CurrentDirectory;
            string finalFileNameWithPath = string.Empty;

            fileName = string.Format("{0}_{1}", fileName, DateTime.Now.ToString("dd-MM-yyyy"));
            finalFileNameWithPath = string.Format("{0}\\{1}.xlsx", currentDirectorypath, fileName);

            if (File.Exists(finalFileNameWithPath))
                File.Delete(finalFileNameWithPath);

            var newFile = new FileInfo(finalFileNameWithPath);

            using (var package = new ExcelPackage(newFile))
            {
                ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(excelSheetName);

                worksheet.Cells["A1"].LoadFromCollection(people, true, TableStyles.None);

But when I export this to xslx I don't get collapse/expand:

UserId  FirstName   LastName    Address
1          John      Doe        Demo_Export_Xls.Address
2          Super     Man    Demo_Export_Xls.Address