This is a migrated thread and some comments may be shown as answers.

RadGrid : Detail Table : Footer Row Export to Excel

1 Answer 157 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rahul Kasar
Top achievements
Rank 1
Rahul Kasar asked on 30 Oct 2013, 11:23 AM
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,

1 Answer, 1 is accepted

Sort by
0
Rahul Kasar
Top achievements
Rank 1
answered on 31 Oct 2013, 07:34 AM
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,
Tags
General Discussions
Asked by
Rahul Kasar
Top achievements
Rank 1
Answers by
Rahul Kasar
Top achievements
Rank 1
Share this question
or