Ejemplo n.º 1
0
        public FileResult Export()
        {
            DataTable dt = new DataTable("ServiceProviders");

            dt.Columns.AddRange(
                new DataColumn[9] {
                new DataColumn("VendorCode"),
                new DataColumn("Name"),
                new DataColumn("Status"),
                new DataColumn("GoLiveDate"),
                new DataColumn("ProjectManager"),
                new DataColumn("Phase"),
                new DataColumn("Fees"),
                new DataColumn("Type"),
                new DataColumn("Update")
            });

            DataTable dtIssue = new DataTable("IssueList");

            dtIssue.Columns.AddRange(
                new DataColumn[5] {
                new DataColumn("VendorCode"),
                new DataColumn("Name"),
                new DataColumn("Item"),
                new DataColumn("Issue"),
                new DataColumn("Owner")
            });

            List <ServiceProviderEntity> serviceProviders = serviceProviderHelper.GetServiceProviders();

            foreach (var serviceProvider in serviceProviders)
            {
                dt.Rows.Add(serviceProvider.Name, serviceProvider.Status, serviceProvider.GoLiveDate, serviceProvider.ProjectManager, serviceProvider.Phase, serviceProvider.Fees, serviceProvider.Type, serviceProvider.Update);

                foreach (var issue in serviceProvider.IssuesList)
                {
                    dtIssue.Rows.Add(issue.VendorCode, serviceProvider.Name, issue.Item, issue.Issue, issue.Owner);
                }
            }

            DataSet ds = new DataSet();

            ds.Tables.Add(dt); ds.Tables.Add(dtIssue);

            using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(ds);
                using (MemoryStream stream = new MemoryStream())
                {
                    wb.SaveAs(stream);
                    return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ServiceProviderDetails.xlsx"));
                }
            }
        }