RadGrid : Detail Table : Footer Row Export to Excel

2 posts, 0 answers
  1. Rahul Kasar
    Rahul Kasar avatar
    14 posts
    Member since:
    Nov 2009

    Posted 30 Oct 2013 Link to this post

    Hi ,

    I am using telerik RadGrid in my application. I want to export the RadGrid Detail Table's and Parent Table's  Footer Row in the excel sheet. I have used the ExcelMLExportRowCreated event to export the footer records which contains the following code :


     if (e.Worksheet.Table.Rows.Count == radGrid.Items.Count + 2)
                {
                  
                 
                  
                    RowElement row = new RowElement();
                    GridFooterItem footer =radGrid.MasterTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;
                    foreach (GridColumn column in radGrid.MasterTableView.Columns)
                    {
                        CellElement cell = new CellElement();
                        String cellText = footer[column.UniqueName].Text;
                        cell.Data.DataItem = cellText == " " ? "" : cellText;
                        row.Cells.Add(cell);
                    }
                   
                    e.Worksheet.Table.Rows.Add(row);
                }

    This works fine for the parent table as we know exact row number for the parent table, But in case of detail table we are not able to determine. Please help me in this.


    Thanks,
  2. Rahul Kasar
    Rahul Kasar avatar
    14 posts
    Member since:
    Nov 2009

    Posted 31 Oct 2013 Link to this post

    Hi,

    I have resolved the issue by finding the detail table and using the same code above.

     foreach (GridDataItem gridDataItem in radGrid.MasterTableView.Items)
                {
                    foreach (GridTableView nestedTableView in gridDataItem.ChildItem.NestedTableViews)
                    {
                        if (e.Worksheet.Table.Rows.Count == nestedTableView.Items.Count + 3)
                        {
                            GridFooterItem detailFooter = nestedTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;

                            RowElement detailRow = new RowElement();
                            foreach (GridColumn column in nestedTableView.Columns)
                            {
                                CellElement cell = new CellElement();
                                String cellText = detailFooter[column.UniqueName].Text;
                                cell.Data.DataItem = cellText == " " ? "" : cellText;
                                detailRow.Cells.Add(cell);
                            }

                            e.Worksheet.Table.Rows.Add(detailRow);
                        }
                    }
                }

    Thanks,
Back to Top