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

SelfHierarchy ExportToExcel and ExportToWord Problem

5 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Barbaros Saglamtimur
Top achievements
Rank 1
Barbaros Saglamtimur asked on 14 Nov 2012, 11:43 AM
Hi,
I am using SelfHierarchy within my RadGrid and would like to use ExportToExcel and ExportToWord functionality. But when I export to excel or word, I see command buttons and other data are exported as-well. For example I use below code to export rows collapsed.
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
 {
     if (e.CommandName.Contains("Export"))
     {
         RadGrid theGrid = (RadGrid)source;
         theGrid.MasterTableView.HierarchyDefaultExpanded = false;
     }
 }
Excel is OK but Word is totally messed. I see buttons and details tables are exported too.

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 14 Nov 2012, 05:49 PM
Hello Barbaros,

Export of self-referencing RadGrid is not supported out-of-the-box and this is why it might behave unexpectedly in some cases. Nevertheless I prepared a simple demo showing how to remove the unwanted controls.
We strongly recommend that you use RadTreeList control instead of RadGrid with self-referencing hierarchy.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Asutosh
Top achievements
Rank 1
answered on 17 Jun 2014, 12:06 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
Marin Bratanov
Telerik team
answered on 17 Jun 2014, 12:16 PM

Hello Asutosh,

I see you have opened several threads with the very same content. I advise that you post only one per issue because this will let the person examining a case focus their efforts in one place instead of spreading information across different channels. I am closing this one, this one and this one and I suggest you continue the discussion here or open a new support ticket from your account in case your issue is urgent.


Regards,

Marin Bratanov
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
Ashwani
Top achievements
Rank 1
answered on 08 Jan 2016, 11:06 AM

I am using this telerik control in my WPF application . I have one button and on click of that button i am exporting RadGridview data to excel. here is my code

 private void btnExportexecl_Click(object sender, RoutedEventArgs e)
        {
            string extension = "xls";
            SaveFileDialog dialog = new SaveFileDialog()
            {
                DefaultExt = extension,
                Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
                FilterIndex = 1
            };
            if (dialog.ShowDialog() == true)
            {
                
                Stream stream = dialog.OpenFile();
                datagrid2.ExportAsync(stream,
                new GridViewExportOptions()
                {
                    Format = ExportFormat.ExcelML,
                    ShowColumnHeaders = true,
                    ShowColumnFooters = true,
                    ShowGroupFooters = false,
                    Encoding=Encoding.Unicode
                }, true);
            }            
        }

but this is exporting only one page .i have also used pagination in that case it exports the current page..i want to export all the 50 pages i tried all the above but Still struggling.. any help will be appreciated. thank you

0
Petya
Telerik team
answered on 11 Jan 2016, 12:52 PM
Hi Ashwani,

When the WPF RadGridView is paged, only the current page is exported. There are a couple of approaches that you can use to avoid that:
1. Use the approach explained here and demonstrated in the ExportPagedDataExcel demo. It includes preserving the page index and size, setting them to 0 in order to export the data and then back to their values.
2. Set the Items property of the export options to your bound collection during the time of the export
datagrid2.ExportAsync(stream,
           new GridViewExportOptions()
           {
               Format = ExportFormat.ExcelML,
               ShowColumnHeaders = true,
               ShowColumnFooters = true,
               ShowGroupFooters = false,
               Encoding=Encoding.Unicode,
                    Items=YourBoundCollection
           }, true);

I hope this is helpful. If you have additional questions about RadGridView for WPF please post them in the designated forum section.

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Barbaros Saglamtimur
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Asutosh
Top achievements
Rank 1
Marin Bratanov
Telerik team
Ashwani
Top achievements
Rank 1
Petya
Telerik team
Share this question
or