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

export hierarchical grid

26 Answers 521 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rieni De Rijke
Top achievements
Rank 1
Rieni De Rijke asked on 22 Jul 2010, 11:49 AM
Is there a way to export a hierarchical radgridview to excel or word?

26 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 22 Jul 2010, 02:21 PM
Hi Rieni De Rijke,

 You can do this very easily. However, there is one caveat - you need to define a RadGridView in a DataTemplate and put it in your XAML resources, because we'll use this RadGridView to export the children. You just need to handle the ElementExported event:

private void Button1_Click(object sender, RoutedEventArgs e)
{
    var saveDialog = new SaveFileDialog();
    if (saveDialog.ShowDialog() == true)
    {
        var stream = saveDialog.OpenFile();
        var streamWriter = new System.IO.StreamWriter(stream);
        streamWriter.Write(this.clubsGrid.ToCsv());
        streamWriter.Close();
        MessageBox.Show("Exported.");
    }
}
private void clubsGrid_ElementExported(object sender, GridViewElementExportedEventArgs e)
{
    if (e.Element == ExportElement.Row)
    {
        var template = this.LayoutRoot.Resources["HierarchyChildTemplate"] as DataTemplate;
        var grid = template.LoadContent() as RadGridView;
        grid.DataContext = e.Context;
        var subExport = grid.ToCsv();
        e.Writer.Write(subExport);
    }
}

Kind regards,
Yavor Georgiev
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
Rieni De Rijke
Top achievements
Rank 1
answered on 26 Jul 2010, 12:33 PM
Thank you for your reply.
It works fine, but only for xml, csv and html.
Although the norwegian characters are messed up.

Excel can not open the xls-file created with ..ToExcelML.

Shouldn't we use the Export-way?

RadGridView1.Export(stream, new GridViewExportOptions())...?
0
Yavor Georgiev
Telerik team
answered on 26 Jul 2010, 12:39 PM
Hi Rieni De Rijke,

 ToCsv, ToHtml and ToExcelMl are just convenience methods that call Export internally. If you're having problems with characters, be sure to set the Culture property of GridViewExportOptions. Also, ExcelML is an XML format, so the correct file extension is XML, not XLS. That is why Excel complains.

All the best,
Yavor Georgiev
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
Rieni De Rijke
Top achievements
Rank 1
answered on 26 Jul 2010, 01:00 PM
I used...
                var stream = saveDialog.OpenFile();
                ...
                using (stream)
                {
                    System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("nb-NO");
                    myMasterGrid.Export(stream,
                                            new GridViewExportOptions()
                                                {
                                                    Format = ExportFormat.ExcelML,
                                                    ShowColumnHeaders = true,
                                                    ShowColumnFooters = true,
                                                    ShowGroupFooters = true,
                                                    Culture = cultureInfo
                                                });
                }
... and saved it as test.xml.
It still won't open in Excel.
How could we tell the "childgrid" to use the same options?

private void clubsGrid_ElementExported(object sender, GridViewElementExportedEventArgs e)
{
    if (e.Element == ExportElement.Row)
    {
        var template = this.LayoutRoot.Resources["HierarchyChildTemplate"] as DataTemplate;
        var grid = template.LoadContent() as RadGridView;
        grid.DataContext = e.Context;
        var subExport = grid.ToExcelML();
        e.Writer.Write(subExport);
    }
}
0
Yavor Georgiev
Telerik team
answered on 26 Jul 2010, 01:14 PM
Hello Rieni De Rijke,

 You need to replace the 'grid.ToExcelML' line in your ElementExported handler with the Export method, passing the appropriate GridViewExportOptions. I'm afraid the ExcelML format does not support hierarchical tables. You should try with HTML.

Sincerely yours,
Yavor Georgiev
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
Rieni De Rijke
Top achievements
Rank 1
answered on 26 Jul 2010, 01:21 PM
What with the "stream"?

private void clubsGrid_ElementExported(object sender, GridViewElementExportedEventArgs e)
{
    if (e.Element == ExportElement.Row)
    {
        var template = this.LayoutRoot.Resources["HierarchyChildTemplate"] as DataTemplate;
        var grid = template.LoadContent() as RadGridView;
        grid.DataContext = e.Context;
        

       
var subExport = ????

           myMasterGrid.Export(stream?????,  new GridViewExportOptions()...

        e.Writer.Write(subExport);
    }
}


0
Yavor Georgiev
Telerik team
answered on 26 Jul 2010, 01:35 PM
Hello Rieni De Rijke,

 

var stream = new MemoryStream();
grid.Export(stream, options);
var subExport = new StreamReader(stream).ReadToEnd();

Also, you should NOT call the Export method on myMasterGrid, but grid, which is the child grid.

Greetings,
Yavor Georgiev
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
Rieni De Rijke
Top achievements
Rank 1
answered on 26 Jul 2010, 01:50 PM
I'm so sorry... The subExport is empty / null...

       private void DgGebyrFakturertElementExported(object sender, GridViewElementExportedEventArgs e)
        {   
            if (e.Element != ExportElement.Row) return;
            var template = Resources["HierarchyChildTemplate"] as DataTemplate;
            var grid = template.LoadContent() as RadGridView;
            Shop shop = (Shop) e.Context;
            grid.ItemsSource = shop.Orders;
           
            System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("nb-NO");
            GridViewExportOptions options = new GridViewExportOptions()
                                                {
                                                    Format = ExportFormat.Html,
                                                    ShowColumnHeaders = true,
                                                    ShowColumnFooters = true,
                                                    ShowGroupFooters = true,
                                                    Culture = cultureInfo
                                                };
            var stream = new MemoryStream();
            grid.Export(stream, options);
            var subExport = new StreamReader(stream).ReadToEnd();
            e.Writer.Write(subExport);
        }

The grid has items, the options is ok, the stream is not null, but the subExport is empty / null / nix...

Is it possible to look at an example where a hierarchical grid is exported?  
0
Yavor Georgiev
Telerik team
answered on 26 Jul 2010, 01:52 PM
Hi Rieni De Rijke,

 Before the 'var subExport = ...' line insert this one:

stream.Seek(0, SeekOrigin.Begin);

Regards,
Yavor Georgiev
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
Rieni De Rijke
Top achievements
Rank 1
answered on 26 Jul 2010, 02:13 PM
Thank you so much for your quick response!

Using ExportFormat.Text all looks well. But a txt-file is not so very usefull.

Using ExportFormat.Csv or ExportFormat.Html works OK, but here the norwegian characters are changed to weird chars...

Using ExportFormat.ExcelML (and filename.xml) can't get open in Excel...

Exporting to Excel is a very important feature for our customers.
I guess I have to use automation to Excel to get this right...
 
0
Vlad
Telerik team
answered on 26 Jul 2010, 02:18 PM
Hi,

 Can you post more info about your Excel version? ExcelML can be opened with Office 2003 and above. 

Regards,
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
Rieni De Rijke
Top achievements
Rank 1
answered on 26 Jul 2010, 02:31 PM
Trying to open an 8export from grid-) excel xml-file gives this error:

XML ANALYSEFEIL: Misformet eller ulovlig behandlingsinstruksjon
 Feil oppstod i eller nedenfor denne elementstakken:
    <ss:Workbook>
     <ss:Worksheet>
      <ss:Table>

Translated something like this:

Analyze-error: Malformed or illegal processing instruction
Error occured in or under this element stack...

The excel-version:
Excel 2007, (12.0.6535.5002) SP2 MSO (12.0.6535.5002)
Part of Microsoft Office Professional Plus 2007.
Norwegian
0
Vlad
Telerik team
answered on 26 Jul 2010, 02:38 PM
Hi,

I forgot to add in my previous reply that hierarchy in ExcelML is not supported. Sorry for this miscommunication!

Regards,
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
Rieni De Rijke
Top achievements
Rank 1
answered on 26 Jul 2010, 02:41 PM
Thank you for your help.

<<Exporting to Excel is a very important feature for our customers.
I guess I have to use automation to Excel to get this right...>>

Do you know if - and when - exporting of hierarchy to Excel will be supported?
0
Vlad
Telerik team
answered on 26 Jul 2010, 02:42 PM
Hi Rieni De Rijke,

 We have plans to add this however I'm not sure if we will be able to include it before the end of the year. 

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
santos
Top achievements
Rank 1
answered on 12 Oct 2010, 07:42 PM
Hello: 

  it is Possible export to excel more two  hierarchy levels?
  it is possible that the code not use datatemplate  to hierarchy, I need dinamyc to export to excel.
  I need see in excel the same data structure  that i see over gridview

I hope anwers, please.
0
Vlad
Telerik team
answered on 13 Oct 2010, 08:35 AM
Hello,

 The closest option we can offer you is demonstrated here

Best wishes,
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
santos
Top achievements
Rank 1
answered on 14 Oct 2010, 02:41 AM

 

in this method, I need exclude rows that not belong to filtering. Actually, the parent row is ok. but hierarchy row is obtaining all children rows.

private void RadGridView1_ElementExported(object sender, GridViewElementExportedEventArgs e)
{
if (e.Element == ExportElement.Row)
{
string codeHTML;
var template = localContainer.Resources["childrenGridView"] as DataTemplate;
var grid = template.LoadContent() as RadGridView;
grid.ItemsSource = localDataSet.Tables[1].Select("ParentIdentificador=" + ((DataRowView)e.Context).Row["Identificador"]);
grid.ShowGroupPanel = false;
grid.IsFilteringAllowed = true;
var subExport = grid.ToHtml();
codeHTML = "<tr><td> </td><td colspan ='10'>" + subExport + "</td></tr>";
e.Writer.Write(codeHTML);
}
}

the line
grid.ItemsSource = localDataSet.Tables[1].Select("ParentIdentificador=" + ((DataRowView)e.Context).Row["Identificador"]);

I get all children data  of row parent. But I need exported only rows that belong to the filter of child row.
help me, please.

 

 

 

 

 

 

 

0
santos
Top achievements
Rank 1
answered on 15 Oct 2010, 03:40 PM
can I exporting the view of example firsk look of gridview with one, two and three tabs to Excel or print preview?
my boss is a demanding person


0
santos
Top achievements
Rank 1
answered on 10 Nov 2010, 07:02 PM
Hello:

 The export data from a gridradview appear the follow at last row of excel.

[QCVG: Key=SARTA DE PRUEBA; ItemCount=1; HasSubgroups=False; ParentGroup=[QCVG: Key=Root; ItemCount=1; HasSubgroups=True; ParentGroup=null];];

I used the Q2 2010 2 0294.  and exist only a group int the panel group.

0
santos
Top achievements
Rank 1
answered on 15 Dec 2010, 04:13 PM
Hi!

I hope any response. The product Telerick is a good product, but I have delivering development the product to the client. you konw this concept.
0
DerekAlfonso
Top achievements
Rank 1
answered on 18 Jan 2011, 11:31 PM
I have this same issue where
[QCVG: Key=Midwest; ItemCount=6; HasSubgroups=False; ParentGroup=[QCVG: Key=Root; ItemCount=300; HasSubgroups=True; ParentGroup=null];];


shows up in the Group Footer in the Excel Export 

Any resolution on this?
0
Vlad
Telerik team
answered on 19 Jan 2011, 08:12 AM
Hi,

 By default the grid will not export group footer cells. You need to set the value using ElementExporting similar to our demo. The WPF version of the code is exactly the same. This feature is supported currently only when exporting with HTML format. 

Best wishes,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Shril
Top achievements
Rank 1
answered on 15 Mar 2011, 05:41 PM
are you guys ever going to add decent grid exporting to the WPF controls... similar to your competitor level of support?

I've just spent time evaluating the WPF controls and for the most part find them quite impressive and simple to use. However, the lack of decent grid exporting is a deal breaker and unfortunately we will not be using your controls because of it.
0
Albert
Top achievements
Rank 1
answered on 10 May 2013, 04:07 PM
Are there any updates on support for this feature?

I would like to export a hierarchical grid to Excel. My user has defined custom styling on specific columns, headers and footers. Conditional cell styling has also been applied using GridViewColumn.CellStyleSelector. I would like these stylings to be exported to Excel too.

Can you, please, supply a sample project that demonstrates how to do this?

Kind Regards,
Albert
0
Dimitrina
Telerik team
answered on 14 May 2013, 11:38 AM
Hi Albert,

You can check the "Exporting RowDetails" WPF Demos on how to export hierarchical GridView. In order to export Styles, you should invoke the Export method with ExportFormat.HTML. Then you can set the e.Styles dictionary with proper CSS values for text alignment of the cell's element when the ElementExporting is raised for the RadGridView. You can refer to the "Exporting" demo for an example.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Rieni De Rijke
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Rieni De Rijke
Top achievements
Rank 1
Vlad
Telerik team
santos
Top achievements
Rank 1
DerekAlfonso
Top achievements
Rank 1
Shril
Top achievements
Rank 1
Albert
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or