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

export to Excel of a three-tiered GridView

3 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
lina fetisova
Top achievements
Rank 1
lina fetisova asked on 09 Aug 2010, 08:59 AM
Good day!
we have a project with Silverlight3 and bot the latest version of Telerik
we export our grids to excel this way:

public static void ExportToXls(RadGridView grid)
        {
            SaveFileDialog textDialog = new SaveFileDialog();
            textDialog.Filter = "XLS Files | *.csv";
            textDialog.DefaultExt = "csv";
            bool? result = textDialog.ShowDialog();
            if (result == true)
            {
                  System.Text.Encoding ascii = System.Text.Encoding.UTF8;
                  Encoding enc=Encoding.GetEncoding("cp1251");
                  string data = ExportExtensions.ToCsv(grid, true);
              //  data+=@"<script type=""text/javascript"">print();</script>";
                  data = data.Replace(",", ";");
                  System.IO.Stream fileStream = textDialog.OpenFile();
                  byte[] contents = enc.GetBytes(data);
                  fileStream.Write(contents, 0, contents.Length);
                  fileStream.Flush();
                  fileStream.Close();
            }
        }


but we have no idea how to make export to excel of three-tiered GridView (somthing like this:

<telerikGridView:RadGridView>
    <telerikGridView:RadGridView.ChildTableDefinitions>               
                <telerikGridView:GridViewTableDefinition>
                    <telerikGridView:GridViewTableDefinition.Relation>
                        <telerikData:PropertyRelation ParentPropertyName="WorkPlaces" />
                    </telerikGridView:GridViewTableDefinition.Relation>
                </telerikGridView:GridViewTableDefinition>                    
            </telerikGridView:RadGridView.ChildTableDefinitions>
            
            <telerikGridView:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerikGridView:RadGridView ItemsSource="{Binding WorkPlaces}" >
                        <telerikGridView:RadGridView.ChildTableDefinitions>
                            <telerikGridView:GridViewTableDefinition>
                                <telerikGridView:GridViewTableDefinition.Relation>
                                    <telerikData:PropertyRelation ParentPropertyName="Licenses" />
                                </telerikGridView:GridViewTableDefinition.Relation>
                            </telerikGridView:GridViewTableDefinition>
                        </telerikGridView:RadGridView.ChildTableDefinitions>

                        <telerikGridView:RadGridView.HierarchyChildTemplate>
                            <DataTemplate>
                                <telerikGridView:RadGridView
                                    ItemsSource="{Binding Licenses}" >
                                </telerikGridView:RadGridView>
                    </telerikGridView:RadGridView>
</telerikGridView:RadGridView>


I want to see information of all the Girds in Excel.
How can I make it?

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 09 Aug 2010, 09:03 AM
Hello ,

 Exporting hierarchal grids currently is not supported. You can use printing instead if this makes sense in your scenario. 

Greetings,
Vlad
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Keerti
Top achievements
Rank 1
answered on 20 May 2011, 05:59 PM
Hi,

Is this functionality available now ? . If its not available can you let us know in which release this will be available.

Thanks & Regards,
Keerti Somasundaram
0
Dimitrina
Telerik team
answered on 25 May 2011, 04:41 PM
Hi Keerti,

 Yes, with the latest release of the RadControls the functionality of exporting Grids in hierarchy is available. You may find it helpful to review this exporting row details online demo, where it is shown how the row details/hierarchy table could be exported.

I am attaching an example project showing how the export is working using HierarchyChildTemplate for two hierarchal child grids.
You have to use the Export method of the RadGridView. In order to implement the hierarchy exporting you need to subscribe to the ElementExported event of the parent grid and inside it add a logic for exporting the related Hierarchal grid.

In the sample project that I am referencing, there are used two DataTemplates for the child grids. The content of the child grid is exported to html and then added to the excel file that is currently being exporting:

private void clubsGrid_ElementExported(...)
      {
          if (e.Element == ExportElement.Row)
          {
              var template = this.LayoutRoot.Resources["Hierarchy1"] as DataTemplate;
              var grid = template.LoadContent() as RadGridView;
              grid.DataContext = e.Context;
              var subExport = grid.ToHtml();
              var columns = this.clubsGrid.Columns.OfType<GridViewBoundColumnBase>().Count();
              var row = string.Format("<tr><td colspan=\"{0}\">{1}</td></tr>", columns, subExport);
              e.Writer.Write(row);
          }
      }

The first Hierarchy child grid should subscribe to its ElementExported event as well, so that its child grid to be exported.

Regards,
Didie
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
lina fetisova
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Keerti
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or