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

Export to Excel for a Rad grid with hierarchical data.

12 Answers 285 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pradeep
Top achievements
Rank 1
pradeep asked on 13 Dec 2010, 02:35 PM
Hi ,

I want to export the data to a excel file from the rad grid which have a hirarchical data.
I tried exporting in normal grid. It works fine. But i dont know how to do the same for hirarchical data.
If anybody knows the answer please let me know.

Thanks & Regards,
Pradeep K S

12 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 14 Dec 2010, 06:42 AM
Hello Pradeep,

Try the following code snippet which shows how to export all hierarchical items.You can loop through each item and expand it before exporting.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.ExportToExcelCommandName)
       {
           foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
           {
              item.Expanded = true;
           }
           RadGrid1.ExportSettings.OpenInNewWindow = true;
           RadGrid1.MasterTableView.ExportToExcel();
       }
   }

Thanks,
Princy.
0
pradeep
Top achievements
Rank 1
answered on 14 Dec 2010, 09:29 AM
Hi Princy,


Thanks for your help. I looked into the code what you sent. But in my case i am not using the built in command header.
I want the export option on click of a button which is present in the form. I tried the below code , but it not worked for me.


foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
           {
              item.Expanded = true;
           }
           RadGrid1.ExportSettings.OpenInNewWindow = true;
           RadGrid1.MasterTableView.ExportToExcel();

Please let me know regardign this.

Regards,
Pradeep k S
0
Princy
Top achievements
Rank 1
answered on 15 Dec 2010, 08:36 AM
Hello Pradeep,

The above code is working fine at my end. How do you populating the grid?I f you are using simple databinding , try to populate the grid using Advanced databinding or using Declarative databinding. There is one forum which discusses almost similar issue. Please go through it and I hope i will help.
RadGrid Export to ExcelML *with* Hierarchy Intact

Thanks,
Princy.

0
Daniel
Telerik team
answered on 16 Dec 2010, 01:13 PM
Hello Pradeep,

Please post your code or provide a runnable demo. This way we will be able to give you to-the-point answer.
Otherwise it will be hard to guess what causes the problem.

Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Asutosh
Top achievements
Rank 1
answered on 16 Jun 2014, 09:39 AM
hi
can i export hierarchy radgrid data to export with simple data binding?
in my code i cant use  ExcelIML  because m binding data to radgrid with simple databinding not advance method.
how can i achieve with simple data binding?
thanks
0
Asutosh
Top achievements
Rank 1
answered on 16 Jun 2014, 09:59 AM
hi princy
your code is working in my case but the problem is i have pagging  in hierarchy data.
that paging is not remove.
can you tell me how to remove that pagging?
i have attached image what i get
0
Asutosh
Top achievements
Rank 1
answered on 17 Jun 2014, 12:05 PM
hi

i am exporting heirarchy radgrid in excel

how to export radgrid in excel without OnNeedDataSource

i am binding datasource to radgrid on button click event 

if i am not use OnNeedDataSource,it give me object reference is null

my code for binding grid is 

 grd_firstchart_aco.DataSource = table;

 grd_firstchart_aco.DataBind();
and code for export to excel is below
  grd_forth_aco.ExportSettings.ExportOnlyData = true;
        grd_forth_aco.ExportSettings.IgnorePaging = true;
        grd_forth_aco.ExportSettings.OpenInNewWindow = true;
        grd_forth_aco.ExportSettings.FileName = "fileName";
        grd_forth_aco.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
        grd_forth_aco.ExportSettings.HideStructureColumns = true;

        grd_forth_aco.MasterTableView.HierarchyDefaultExpanded = true;
        grd_forth_aco.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;

        grd_forth_aco.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
        grd_forth_aco.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;

        grd_forth_aco.MasterTableView.ExportToExcel();
thanks


0
Daniel
Telerik team
answered on 19 Jun 2014, 08:25 AM
Hello Asutosh,

You have to use advanced data-binding in a setup with hierarchy and export (please see the first topic). Simple data-binding is not supported for such complex scenarios.
Simple Data-binding
Advanced Data-binding (Using NeedDataSource Event)

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Asutosh
Top achievements
Rank 1
answered on 19 Jun 2014, 10:37 AM
thanks for your reply but let me explain my criteria.

i have telerik chart on which when i press show data button it opens radwindot popup in which i have implemented hirarchical telerik grid. i sometime apply filters on chart and that click on show data so it shows me corresponding grid after applying filters. and i want export to excel button to only export data which i can see at first and if i have applied any filters than according to those filters.
0
Daniel
Telerik team
answered on 23 Jun 2014, 10:51 AM
Hello Asutosh,

I'm afraid this is not supported as I mentioned in my previous reply. The only idea I have in mind and which might work in this scenario is to export to HTML format (instead of ExcelML) with all utility properties disabled (ExportOnlyData, IgnorePaging, HideStructureColumns, etc) because they will cause rebind which won't work with simple data-binding.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Asutosh
Top achievements
Rank 1
answered on 23 Jun 2014, 11:45 AM
hi 
thanks for your reply
my problem has been solve
my hierarchy gridview has pagging and size iz 10
now the problem is that when i export data as excel
only 10 rows of hierarchy grid export in excel
i use below code to export
code:
  gridname.ExportSettings.FileName = "filename";
            gridname.ExportSettings.IgnorePaging = true;
            gridname.ExportSettings.ExportOnlyData = true;
            gridname.ExportSettings.OpenInNewWindow = true;
            gridname.MasterTableView.UseAllDataFields = true;
            gridname.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;

            gridname.MasterTableView.HierarchyDefaultExpanded = true;
            gridname.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;

            gridname.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
            gridname.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;

            gridname.MasterTableView.ExportToExcel();


0
Daniel
Telerik team
answered on 26 Jun 2014, 10:50 AM
Hello Asutosh,

I suppose that you are using the NeedDataSource approach now. If this is so, could you check whether the same problem is reproducible with the HTML format?

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
pradeep
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
pradeep
Top achievements
Rank 1
Daniel
Telerik team
Asutosh
Top achievements
Rank 1
Share this question
or