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

How export a Grid Hierarchy to Excel with to Telerik's controls for WPF?

3 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alejandro
Top achievements
Rank 1
Alejandro asked on 16 Jan 2012, 11:51 PM
Telerik RadControls for WPF Q1 2011 SP1

I have a grid hierarchy, I want to Export to Exel.
I used this code, but I don't have anything of the Grid Hierarchy in Excel

SaveFileDialog dialog = new SaveFileDialog();
           dialog.DefaultExt = extension;
           dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", "xls", "Excel");
           dialog.FilterIndex = 1;
           if (dialog.ShowDialog() == true)
           {
               using (Stream stream = dialog.OpenFile())
               {
                   GridViewExportOptions exportOptions = new GridViewExportOptions();
                   exportOptions.Format = format;
                   exportOptions.ShowColumnFooters = true;
                   exportOptions.ShowColumnHeaders = true;
                   exportOptions.ShowGroupFooters = true;
                   RadGridView1.Export(stream, exportOptions);
               }
           }

I read foros where the controls don't support this Export to Excel.
Please, really I need your help.


3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 17 Jan 2012, 09:06 AM
Hello,

Please take a look at this forum post about exporting hierarchal grid.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Alejandro
Top achievements
Rank 1
answered on 18 Jan 2012, 06:11 PM
Sorry Didie, but this example isn't similar to my proyect.
I have the Conexion to DB with EntityFramework.

Netro_Cartera_44Entities m_CARTERAEntities;
ObservableCollection<nsp_get_PagosFondoSR_Netro_Result> PagosFondoSR_Netro;
ObservableCollection<nsp_get_PagosDetalleFondoSR_Netro_Result> Prueba;
 
public MainWindow()
{
    try
    {
        InitializeComponent();
        m_CARTERAEntities = new Netro_Cartera_44Entities();
        m_CARTERAEntities.CommandTimeout = 700;
        var temp = m_CARTERAEntities.nsp_get_PagosFondoSR_Netro();
        PagosFondoSR_Netro = new ObservableCollection<nsp_get_PagosFondoSR_Netro_Result>(temp);
 
        foreach (var item in PagosFondoSR_Netro)
        {
            var temp2 = m_CARTERAEntities.nsp_get_PagosDetalleFondoSR_Netro(item.NumSolicitud);
            item.DetallePagosDetalleFondoSR_Netro = new ObservableCollection<nsp_get_PagosDetalleFondoSR_Netro_Result>(temp2);
        }
 
        RadGridView1.ItemsSource = PagosFondoSR_Netro;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message.ToString());
    }
}

private void RadGridView1_DataLoading(object sender, GridViewDataLoadingEventArgs e)
        {
            GridViewDataControl dataControl = (GridViewDataControl)sender;
            if (dataControl.ParentRow != null)
            {
                dataControl.CanUserFreezeColumns = false;
                dataControl.ShowGroupPanel = false;
                dataControl.AutoGenerateColumns = false;
 
                GridViewDataColumn column = new GridViewDataColumn();
                column.Header = "Importe";
                column.DataMemberBinding = new System.Windows.Data.Binding("Importe");
                dataControl.Columns.Add(column);
 
                GridViewDataColumn column2 = new GridViewDataColumn();
                column2.Header = "Interes";
                column2.DataMemberBinding = new System.Windows.Data.Binding("Interes");
                dataControl.Columns.Add(column2);
 
                GridViewDataColumn column3 = new GridViewDataColumn();
                column3.Header = "Numero Amortizacion";
                column3.DataMemberBinding = new System.Windows.Data.Binding("NumeroAmortizacion");
                dataControl.Columns.Add(column3);
            }
        }
0
Dimitrina
Telerik team
answered on 19 Jan 2012, 05:19 PM
Hello,

 In the ElementExported event you have the context of the currently exported item (e.Context). From it, you may find the details for your hierarchy and export them as suggested in the forum thread.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Alejandro
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Alejandro
Top achievements
Rank 1
Share this question
or