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

Export to Excel the heirarchial RadGridView

5 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Elver Emilio Cano Cardona
Top achievements
Rank 1
Elver Emilio Cano Cardona asked on 20 Apr 2011, 02:36 PM
Hi.. how are you

          Is there a method or a work around to Export the heirarchial RadGridView data to Excel?

I tried the following methods:
  1. Using Telerik.Data.RadGridViewExcelExporter 
  2. Using RadGridReportingLite. sample code using RadLite.

            (RadGridReport rep = new RadGridReport(strFileName);

 

            rep.ReportFormShow(

this, this.radGridView1);

 

 

 

 

both of them are exporting only MasterTable Data. child Table data is not exported.

Please suggest any solution.

Thank you,
Regards
Elver Emilio

5 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 20 Apr 2011, 05:01 PM
Hello,

As far as I'm aware, this is not yet supported by the RadGridView. Only the Master Template as you have suggested can be exported at this time.
Regards,
Richard
0
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 20 Apr 2011, 05:07 PM
Hi....Richard..

I was looking in the forums.. and i found this.. somebody of telerik write this.. i have  a doubt.. this is true????

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Actually, I have some good news here. We have implemented exporting hierarchical data in our latest release Q1 2011 (2011.1.11.315). You just have to set the ExportHierarchy property to true:
ExportToExcelML excelExporter = new ExportToExcelML(radGridView);
excelExporter.ExportHierarchy = true;
excelExporter.ExportVisualSettings = true;
excelExporter.RunExport(filePath);
Let me know if you have any additional questions.

All the best,
Martin Vasilev
the Telerik team
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0
Richard Slade
Top achievements
Rank 2
answered on 20 Apr 2011, 05:20 PM
Hello,

Please accept my apologies. I completely forgot that this had been implemented. It's correct that this is now possible. Here is a small sample for you to try.

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.Data;
using Telerik.WinControls.UI.Export;
  
  
namespace RadGridView_Hierarchy_CS
{
    public partial class Form1 : Form
    {
  
        private List<Person> people = new List<Person>();
        private List<Address> addresses = new List<Address>();
  
        public Form1()
        {
            InitializeComponent();
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            FillPeople();
            FillAddresses();
  
            radGridView1.DataSource = people;
  
            GridViewTemplate template = new GridViewTemplate();
            template.DataSource = addresses;
            radGridView1.MasterTemplate.Templates.Add(template);
  
            GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
            relation.ChildTemplate = template;
            relation.RelationName = "PersonAddress";
            relation.ParentColumnNames.Add("Id");
            relation.ChildColumnNames.Add("PersonId");
            radGridView1.Relations.Add(relation);
  
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        }
  
  
  
  
        private void FillPeople()
        {
            Person richard = new Person();
            richard.Name = "Richard";
            richard.Id = 1;
            people.Add(richard);
            Person bob = new Person();
            bob.Name = "Bob";
            bob.Id = 2;
            people.Add(bob);
            Person mike = new Person();
            mike.Name = "Mike";
            mike.Id = 3;
            people.Add(mike);
        }
  
        private void FillAddresses()
        {
            Address house1 = new Address();
            house1.PersonId = 1;
            house1.Id = 1;
            house1.theAddress = "1 The Mews";
            house1.theAddress2 = "1 The Mews";
            house1.theAddress3 = "1 The Mews";
            house1.theAddress4 = "1 The Mews";
            addresses.Add(house1);
            Address house2 = new Address();
            house2.PersonId = 2;
            house2.Id = 2;
            house2.theAddress = "2 The Mews";
            house2.theAddress2 = "1 The Mews";
            house2.theAddress3 = "1 The Mews";
            house2.theAddress4 = "1 The Mews";
            addresses.Add(house2);
            Address house3 = new Address();
            house3.PersonId = 2;
            house3.Id = 3;
            house3.theAddress = "3 The Mews";
            house3.theAddress2 = "1 The Mews";
            house3.theAddress3 = "1 The Mews";
            house3.theAddress4 = "1 The Mews";
            addresses.Add(house3);
        }
  
  
  
        private void radButton1_Click(object sender, EventArgs e)
        {
            ExportToExcelML exporter = new ExportToExcelML(this.radGridView1);
            exporter.ExportHierarchy = true;
            exporter.RunExport(@"C:\Users\Richard\Documents\MyFile.xls"); //replace with your own
        }
  
  
  
  
    }
  
    class Person 
    {     
        public int Id {get;set;}     
        public string Name {get;set;}     
                
          
        public Person()     
        { }      
          
    }
   
    class Address  
    {
        public int Id { get; set; }   
        public int PersonId {get;set;}    
        public string theAddress {get;set;}
        public string theAddress2 { get; set; }
        public string theAddress3 { get; set; }
        public string theAddress4 { get; set; }   
  
        public Address()
        { }
    }
}

Designer File
namespace RadGridView_Hierarchy_CS
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components;
  
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
  
        #region Windows Form Designer generated code
  
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            this.radButton1 = new Telerik.WinControls.UI.RadButton();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).BeginInit();
            this.SuspendLayout();
            // 
            // radGridView1
            // 
            this.radGridView1.Location = new System.Drawing.Point(0, 0);
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.Size = new System.Drawing.Size(229, 342);
            this.radGridView1.TabIndex = 0;
            this.radGridView1.Text = "radGridView1";
            // 
            // radButton1
            // 
            this.radButton1.Location = new System.Drawing.Point(65, 368);
            this.radButton1.Name = "radButton1";
            this.radButton1.Size = new System.Drawing.Size(130, 24);
            this.radButton1.TabIndex = 1;
            this.radButton1.Text = "radButton1";
            this.radButton1.Click += new System.EventHandler(this.radButton1_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(229, 409);
            this.Controls.Add(this.radButton1);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).EndInit();
            this.ResumeLayout(false);
  
        }
  
        #endregion
  
        private Telerik.WinControls.UI.RadGridView radGridView1;
        private Telerik.WinControls.UI.RadButton radButton1;
    }
}

Hope that helps but please let me know if you have any questions
Richard
0
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 20 Apr 2011, 05:23 PM
hi... i am so glad.. it solve a lot problems.. for my applications.. i am going to run this example..

thanks a lot...
0
Richard Slade
Top achievements
Rank 2
answered on 20 Apr 2011, 05:28 PM
You're welcome. If you find this helps please remember to mark as answer, and again, apologies for not giving you the correct information the first time.
Richard
Tags
GridView
Asked by
Elver Emilio Cano Cardona
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Elver Emilio Cano Cardona
Top achievements
Rank 1
Share this question
or