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

Export GridView with template to Excel

7 Answers 144 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 12 Jul 2010, 02:22 PM

Hello.. how are you..

i have the next scene.. i have a grid nest into the other grid i am using the tools to export of telerik.. its a example:

 

public void Export(String sFilepath, RadGridView grvExportExcel)

{

ExportToExcelML exporter = new ExportToExcelML(grvExportExcel);

exporter.SummariesExportOption = SummariesOption.ExportAll;

exporter.RunExport(sFilepath);

}

but its doesn't work .. when i run this function its make the file succesfully but only export the primary grid and the template not...
i need export all information of the grid... if somebody can help me.. i will pleasure.. for your help.

 

public void Export(String sFilepath, GridViewTemplate grvtExportExcel)

{

RadGridView rgvGrid = new RadGridView();

foreach (GridViewDataColumn c in grvtExportExcel.Columns)

{

rgvGrid.Columns.Add(c);

}

foreach (GridViewDataRowInfo d in grvtExportExcel.Rows)

{

rgvGrid.Rows.AddNew(d);

}

ExportToExcelML exporter = new ExportToExcelML(rgvGrid);

exporter.SummariesExportOption = SummariesOption.ExportAll;

exporter.RunExport(sFilepath);

}

}

but its doesn't work neither....

regards...
thanks for your help.

7 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 15 Jul 2010, 03:39 PM
Hi Elver Emilio Cano Cardona,

I have already answered your question in your support thread, which you have created for the same question. Still, I am posting the answer here as well, in case our community is interested.

Actually, the exporting methods of RadGridView do not support exporting hierarchy data. The grid always exports the content of the MasterGridViewTemplate. The main reason for this is that MS Excel itself does not support hierarchical data.

Nevertheless, we are considering the implementation of exporting hierarchical data (in a flat structure) in a future release. Any suggestions on how you think the hierarchical data should be represented in Excel will be highly appreciated.

Regards,
Martin Vasilev
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
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 22 Jul 2010, 01:53 PM
hello..
You are right.. its bad news for me because rith now i am doing a application that used a hierarchical GridView let me know more or less to when Telerik they can implement this functionality with the grids? , I can send you what i am doing right now.. with more details..
Thanks for your help
regards.
Elver Cano
0
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 23 Jul 2010, 02:10 PM
 i have the next scene.. i have a grid nest into the other grid i am using the tools to export of telerik.. its a example:

I have one grid with a Template. Then main grid has header with five columns and its relation with the template with their details.
when i export the information only export the header but the details nothing..that is my problem, you told me that its doesn't support that functionality but you told me too that Telerik is working in that to resolve this problem.. in a next release, rigt now i am doing a application about CollectionManagment and the only thing that i need to finisg is that.. to export to excel. i will be grateful. if you say me something to resolve this problem with that control.

Best Wish.
Elver Cano
0
Martin Vasilev
Telerik team
answered on 26 Jul 2010, 05:34 PM
Hi Elver Emilio Cano Cardona,

Thank you for getting back to me.

I am not sure what exactly is your issue with ExportToExcelML. Currently, we do not support exporting child views and hierarchical data. We are considering the inclusion of this feature in the next major release, but our full road map is not yet ready and I cannot be sure about the time frame.

Also I would like to note that we have discovered an issue with latest version Q2 2010 and in some situations the exporting does not export any data from hierarchical grids: the end file contains only the header row. We have already addressed that and the fix will be presented in the upcoming service pack release.

Let me know if you have any additional questions.

Kind regards,
Martin Vasilev
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
KawaUser
Top achievements
Rank 2
answered on 09 May 2011, 09:06 PM
Was this ever implemented in to a new release? I am now in the same predicament.

Thank you,
Chuck
0
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 09 May 2011, 09:36 PM

Hello..

but somebody send me the next information...i couldn't make it yet but it works i think.. with Q1 2011

From: Richard Slade
Date: 4/20/2011 12:20:24 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.

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingTelerik.WinControls.UI;

usingTelerik.Data;

usingTelerik.WinControls.UI.Export;

  

  

namespaceRadGridView_Hierarchy_CS

{

    publicpartialclassForm1 : Form

    {

  

        privateList<Person> people = newList<Person>();

        privateList<Address> addresses = newList<Address>();

  

        publicForm1()

        {

            InitializeComponent();

        }

  

        privatevoidForm1_Load(objectsender, EventArgs e)

        {

            FillPeople();

            FillAddresses();

  

            radGridView1.DataSource = people;

  

            GridViewTemplate template = newGridViewTemplate();

            template.DataSource = addresses;

            radGridView1.MasterTemplate.Templates.Add(template);

  

            GridViewRelation relation = newGridViewRelation(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;

        }

  

  

  

  

        privatevoidFillPeople()

        {

            Person richard = newPerson();

            richard.Name = "Richard";

            richard.Id = 1;

            people.Add(richard);

            Person bob = newPerson();

            bob.Name = "Bob";

            bob.Id = 2;

            people.Add(bob);

            Person mike = newPerson();

            mike.Name = "Mike";

            mike.Id = 3;

            people.Add(mike);

        }

  

        privatevoidFillAddresses()

        {

            Address house1 = newAddress();

            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 = newAddress();

            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 = newAddress();

            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);

        }

  

  

  

        privatevoidradButton1_Click(objectsender, EventArgs e)

        {

            ExportToExcelML exporter = newExportToExcelML(this.radGridView1);

            exporter.ExportHierarchy = true;

            exporter.RunExport(@"C:\Users\Richard\Documents\MyFile.xls"); //replace with your own

        }

  

  

  

  

    }

  

    classPerson 

    {     

        publicintId {get;set;}     

        publicstringName {get;set;}     

                

          

        publicPerson()     

        { }      

          

    }

   

    classAddress  

    {

        publicintId { get; set; }   

        publicintPersonId {get;set;}    

        publicstringtheAddress {get;set;}

        publicstringtheAddress2 { get; set; }

        publicstringtheAddress3 { get; set; }

        publicstringtheAddress4 { get; set; }   

  

        publicAddress()

        { }

    }

}


Designer File

namespaceRadGridView_Hierarchy_CS

{

    partialclassForm1

    {

        /// <summary>

        /// Required designer variable.

        /// </summary>

        privateSystem.ComponentModel.IContainer components;

  

        /// <summary>

        /// Clean up any resources being used.

        /// </summary>

        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protectedoverridevoidDispose(booldisposing)

        {

            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>

        privatevoidInitializeComponent()

        {

            this.radGridView1 = newTelerik.WinControls.UI.RadGridView();

            this.radButton1 = newTelerik.WinControls.UI.RadButton();

            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();

            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).BeginInit();

            this.SuspendLayout();

            // 

            // radGridView1

            // 

            this.radGridView1.Location = newSystem.Drawing.Point(0, 0);

            this.radGridView1.Name = "radGridView1";

            this.radGridView1.Size = newSystem.Drawing.Size(229, 342);

            this.radGridView1.TabIndex = 0;

            this.radGridView1.Text = "radGridView1";

            // 

            // radButton1

            // 

            this.radButton1.Location = newSystem.Drawing.Point(65, 368);

            this.radButton1.Name = "radButton1";

            this.radButton1.Size = newSystem.Drawing.Size(130, 24);

            this.radButton1.TabIndex = 1;

            this.radButton1.Text = "radButton1";

            this.radButton1.Click += newSystem.EventHandler(this.radButton1_Click);

            // 

            // Form1

            // 

            this.AutoScaleDimensions = newSystem.Drawing.SizeF(6F, 13F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = newSystem.Drawing.Size(229, 409);

            this.Controls.Add(this.radButton1);

            this.Controls.Add(this.radGridView1);

            this.Name = "Form1";

            this.Text = "Form1";

            this.Load += newSystem.EventHandler(this.Form1_Load);

            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();

            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).EndInit();

            this.ResumeLayout(false);

  

        }

  

        #endregion

  

        privateTelerik.WinControls.UI.RadGridView radGridView1;

        privateTelerik.WinControls.UI.RadButton radButton1;

    }

}


Hope that helps but please let me know if you have any questions
Richard

0
Martin Vasilev
Telerik team
answered on 12 May 2011, 10:13 PM
Hello guys,

I can confirm that we have introduced exporting hierarchical and grouped data in Q1 2011 release. To enable this feature, just use the ExportHierarchy property:
ExportToExcelML exporter = new ExportToExcelML(this.radGridView1); 
exporter.ExportHierarchy = true;
exporter.RunExport("MyPath");


Greetings,
Martin Vasilev
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Elver Emilio Cano Cardona
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Elver Emilio Cano Cardona
Top achievements
Rank 1
KawaUser
Top achievements
Rank 2
Share this question
or