Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
500
Export to Excel without manually creating the excel workbook
posted

Hi, I am using ASP.Net MVC. On Ignite UI's website , The sample contains numerous method including method that set up the columns and rows of the worksheet manually according to the grid and then the data is exported to it.

Isn't there a shorter way of exporting to Excel without manually designing the layout of the Excel Workbook? Why cant the grid provide all the column settings to the Excel Exporter,

I think in WebForms we have to write only one line like this --> this.ultraGridExcelExporter1.Export(this.ultraGrid1, "C:\\GridData.xls");

This line exports the data of the grid directly to the excel sheet without specifying manually about the columns and rows of the grid, Can we do this in Ignite UI?

Why do we have to specify like this(FROM IGNITE UI SAMPLE) :

 public void PopulateExcelWorkbook(List<Order> data)
            {
                Worksheet currentWorksheet = this.excelWorkbook.Worksheets.Add("WorkSheet1");

                foreach (var cell in currentWorksheet.GetRegion("A1:D1"))
                {
                    cell.CellFormat.Fill = CellFill.CreateSolidFill(Color.Gray);
                    cell.CellFormat.Font.ColorInfo = new WorkbookColorInfo(Color.White);
                }

                currentWorksheet.Rows[0].Cells[0].Value = "Order ID";
                currentWorksheet.Rows[0].Cells[1].Value = "Contact Name";
                currentWorksheet.Rows[0].Cells[2].Value = "Shipping Address";
                currentWorksheet.Rows[0].Cells[3].Value = "Order Date";
                
                currentWorksheet.Columns[0].Width = 3000;
                currentWorksheet.Columns[0].CellFormat.Alignment = HorizontalCellAlignment.Left;
                currentWorksheet.Columns[1].Width = 7100;
                currentWorksheet.Columns[2].Width = 3000;
                currentWorksheet.Columns[2].CellFormat.Alignment = HorizontalCellAlignment.Left;
                currentWorksheet.Columns[3].Width = 6100;

                int i = 1;
                foreach (Order order in data)
                {
                    currentWorksheet.Rows[i].Cells[0].Value = order.OrderID;
                    currentWorksheet.Rows[i].Cells[1].Value = order.ContactName;
                    currentWorksheet.Rows[i].Cells[2].Value = order.ShipAddress;
                    currentWorksheet.Rows[i].Cells[3].Value = order.OrderDate != null ? string.Format("{0:d}", order.OrderDate) : "";
                    i++;
                }
            }

Parents Reply Children