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

Does ExportToExcelML support exporting child templates?

10 Answers 312 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deepak
Top achievements
Rank 1
Deepak asked on 08 Feb 2011, 03:00 PM
If yes, then when I try to export, I get this error...

System.InvalidOperationException: {"Could not find neighbour element!"}

and the stack trace is at

Telerik.WinControls.UI.Export.ExportToExcelML.SearchForNeighbourElement(List`1 radElementList, Int32 index) at Telerik.WinControls.UI.Export.ExportToExcelML.CreateStyleElement(GridViewRowInfo gridViewRowInfo, Int32 cellIndex) at Telerik.WinControls.UI.Export.ExportToExcelML.CreateRowElement(WorkBookElement workbook, GridViewRowInfo gridViewRowInfo) at Telerik.WinControls.UI.Export.ExportToExcelML.AddWorkSheetWithHeaderRow(WorkBookElement workbook, FileStream fileStream, Int32& currentSheet, Int32& currentRow) at Telerik.WinControls.UI.Export.ExportToExcelML.RunExport(String fileName)


The code being used is
Dim cc As New ExportToExcelML(grid)
 cc.ExportVisualSettings = True
 cc.RunExport(saveFileDialog1.FileName)

10 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 08 Feb 2011, 03:18 PM
Hi Deepak,

As far as I'm aware, exporting hierarcical data is not supported because Excel does not support hierarcical data. However, yuo should not be getting an error. The exporter should be just exporting the Master Tempalte rows.

Please can you try the following

Designer File
namespace RadGridView_hierarchy_C
{
    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()
        {
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn1 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn2 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 = new Telerik.WinControls.UI.GridViewTextBoxColumn();
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn3 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn4 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).BeginInit();
            this.SuspendLayout();
            //  
            // radGridView1 
            //  
            this.radGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.radGridView1.Location = new System.Drawing.Point(12, 35);
            //  
            // radGridView1 
            //  
  
            gridViewDecimalColumn1.DecimalPlaces = 0;
            gridViewDecimalColumn1.FieldName = "ID";
            gridViewDecimalColumn1.FormatString = "";
            gridViewDecimalColumn1.HeaderText = "ID";
            gridViewDecimalColumn1.IsVisible = false;
            gridViewDecimalColumn1.Name = "ID";
            gridViewDecimalColumn1.TextAlignment = System.Drawing.ContentAlignment.MiddleRight;
            gridViewDecimalColumn2.DecimalPlaces = 0;
            gridViewDecimalColumn2.FieldName = "ID2";
            gridViewDecimalColumn2.FormatString = "";
            gridViewDecimalColumn2.HeaderText = "ID2";
            gridViewDecimalColumn2.IsVisible = false;
            gridViewDecimalColumn2.Name = "ID2";
            gridViewDecimalColumn2.TextAlignment = System.Drawing.ContentAlignment.MiddleRight;
            gridViewTextBoxColumn1.FieldName = "Name";
            gridViewTextBoxColumn1.FormatString = "";
            gridViewTextBoxColumn1.HeaderText = "Name";
            gridViewTextBoxColumn1.Name = "Name";
            gridViewTextBoxColumn1.ReadOnly = true;
            gridViewTextBoxColumn1.Width = 100;
            gridViewDecimalColumn3.FieldName = "Price";
            gridViewDecimalColumn3.FormatString = "";
            gridViewDecimalColumn3.HeaderText = "Price";
            gridViewDecimalColumn3.Name = "Price";
            gridViewDecimalColumn3.TextAlignment = System.Drawing.ContentAlignment.MiddleRight;
            gridViewDecimalColumn3.Width = 150;
            gridViewDecimalColumn4.DecimalPlaces = 0;
            gridViewDecimalColumn4.FieldName = "Qty";
            gridViewDecimalColumn4.FormatString = "";
            gridViewDecimalColumn4.HeaderText = "Qty";
            gridViewDecimalColumn4.Maximum = new decimal(new int[] { 
        100, 
        0, 
        0, 
        0});
            gridViewDecimalColumn4.Minimum = new decimal(new int[] { 
        1, 
        0, 
        0, 
        0});
            gridViewDecimalColumn4.Name = "Qty";
            gridViewDecimalColumn4.TextAlignment = System.Drawing.ContentAlignment.MiddleRight;
            gridViewDecimalColumn4.Width = 150;
            this.radGridView1.MasterTemplate.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { 
        gridViewDecimalColumn1, 
        gridViewDecimalColumn2, 
        gridViewTextBoxColumn1, 
        gridViewDecimalColumn3, 
        gridViewDecimalColumn4});
            this.radGridView1.Name = "radGridView1";
            //
            //  
            //  
            //  
            //
            this.radGridView1.Size = new System.Drawing.Size(604, 379);
            this.radGridView1.TabIndex = 0;
            this.radGridView1.Text = "radGridView1";
            //  
            // Form1 
            //  
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(628, 426);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            //this.Load += new System.EventHandler(this.Form1_Load); 
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
  
            this.ResumeLayout(false);
        }
  
        #endregion
  
        private Telerik.WinControls.UI.RadGridView radGridView1;
    }
}

Form.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;
using Telerik.WinControls.UI;
using Telerik.WinControls.RadControlSpy;
using System.Globalization;
using Telerik.WinControls.UI.Export;
using Telerik.WinControls.Data;
  
namespace RadGridView_hierarchy_C
{
    public partial class Form1 : Form
    {
          
  
        public Form1()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
  
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
  
            List<Person> People = new List<Person>();
            List<Car> Cars = new List<Car>();
            List<CarYear> CarYears = new List<CarYear>();
  
            // load primary data source 
            People.Add(new Person(1, 101, "Bob", 204.50M, 1));
            People.Add(new Person(2, 102, "Rob", 208.00M, 1));
            People.Add(new Person(3, 103, "Eric", 300.00M, 1));
            this.radGridView1.DataSource = People;
  
            GridViewTemplate carTemplate = new GridViewTemplate();
            Cars.Add(new Car(101, 1, "Ford", 100.50M, 1));
            Cars.Add(new Car(102, 2, "BMW", 104, 1));
            Cars.Add(new Car(102, 6, "BMW", 104, 1));
            Cars.Add(new Car(102, 7, "BMW", 104, 1));
            Cars.Add(new Car(102, 3, "Mazda", 100, 1));
            Cars.Add(new Car(102, 8, "Mazda", 100, 1));
            Cars.Add(new Car(102, 4, "Merc", 100, 1));
            Cars.Add(new Car(103, 5, "Honda", 100, 1));
            carTemplate.DataSource = Cars;
  
  
            GridViewTemplate carYearTemplate = new GridViewTemplate();
            CarYears.Add(new CarYear(1, 2004, "Ford", 100));
            CarYears.Add(new CarYear(2, 2000, "BMW", 104));
            CarYears.Add(new CarYear(2, 2001, "BMW", 104));
            CarYears.Add(new CarYear(2, 2002, "BMW", 104));
            CarYears.Add(new CarYear(2, 2003, "BMW", 104));
            CarYears.Add(new CarYear(2, 2004, "BMW", 104));
            CarYears.Add(new CarYear(2, 2005, "BMW", 104));
            CarYears.Add(new CarYear(3, 2004, "Mazda", 100));
            CarYears.Add(new CarYear(4, 2007, "Merc", 100));
            CarYears.Add(new CarYear(5, 2010, "Honda", 100));
            CarYears.Add(new CarYear(6, 2004, "M3", 100));
            CarYears.Add(new CarYear(7, 2011, "M3", 100));
            CarYears.Add(new CarYear(8, 2000, "Mazda", 100));
            CarYears.Add(new CarYear(8, 2001, "Mazda", 100));
            CarYears.Add(new CarYear(8, 2002, "Mazda", 100));
            CarYears.Add(new CarYear(8, 2003, "Mazda", 100));
            CarYears.Add(new CarYear(8, 2004, "Mazda", 100));
            CarYears.Add(new CarYear(8, 2005, "Mazda", 100));
            CarYears.Add(new CarYear(8, 2006, "Mazda", 100));
            CarYears.Add(new CarYear(8, 2007, "Mazda", 100));
            carYearTemplate.DataSource = CarYears;
  
  
            // Now create first relation 
            GridViewRelation carsRelation = new GridViewRelation(this.radGridView1.MasterTemplate);
            carsRelation.ChildTemplate = carTemplate;
            carsRelation.RelationName = "ParentChild";
            carsRelation.ParentColumnNames.Add("ID2");
            carsRelation.ChildColumnNames.Add("ID");
            this.radGridView1.Relations.Add(carsRelation);
  
            GridViewRelation carYearsRelation = new GridViewRelation(carTemplate, carYearTemplate);
            carYearsRelation.RelationName = "ChildGrandChild";
            carYearsRelation.ParentColumnNames.Add("ID2");
            carYearsRelation.ChildColumnNames.Add("ID");
            this.radGridView1.Relations.Add(carYearsRelation);
  
            this.radGridView1.MasterTemplate.Templates.Add(carTemplate);
            this.radGridView1.MasterTemplate.Templates[0].Templates.Add(carYearTemplate);
  
            this.radGridView1.MasterTemplate.Templates[0].AllowAddNewRow = false;
            this.radGridView1.MasterTemplate.Templates[0].Templates[0].AllowAddNewRow = false;
  
  
            this.radGridView1.MasterTemplate.Templates[0].Columns["ID"].IsVisible = false;
            this.radGridView1.MasterTemplate.Templates[0].Columns["ID2"].IsVisible = false;
            this.radGridView1.MasterTemplate.Templates[0].Columns["Model"].Width = 150;
            this.radGridView1.MasterTemplate.Templates[0].Columns["Model"].ReadOnly = true;
            this.radGridView1.MasterTemplate.Templates[0].Columns["Qty"].Width = 150;
            this.radGridView1.MasterTemplate.Templates[0].Columns["Price"].Width = 150;
            this.radGridView1.MasterTemplate.Templates[0].Templates[0].Columns["ID"].IsVisible = false;
            this.radGridView1.MasterTemplate.Templates[0].Templates[0].Columns["Model"].IsVisible = false;
            this.radGridView1.MasterTemplate.Templates[0].Templates[0].Columns["Year"].Width = 150;
            this.radGridView1.MasterTemplate.Templates[0].Templates[0].Columns["Year"].ReadOnly = true;
              
            this.radGridView1.MasterView.ChildRows[1].IsExpanded = true;
            this.radGridView1.MasterView.ChildRows[1].ChildRows[0].IsExpanded = true;
  
              
  
            this.radGridView1.AutoGenerateColumns = false;
            this.radGridView1.AutoSizeRows = true;
            this.radGridView1.EnableAlternatingRowColor = true;
            this.radGridView1.ReadOnly = false;
            this.radGridView1.AutoGenerateHierarchy = false;
  
            ExportToExcelML export = new ExportToExcelML(this.radGridView1);
            export.ExportVisualSettings = true;
            export.RunExport(@"your file path....xls");
  
        }
  
    }
  
  
    public class Person
    {
        public int ID { get; set; }
        public int ID2 { get; set; }
        public string Name { get; set; }
        public decimal Price { get; set; }
        public decimal Qty { get; set; }
  
        public Person(int id, int id2, string name, decimal price, decimal qty)
        {
            ID = id;
            ID2 = id2;
            Name = name;
            Price = price;
            Qty = qty;
        }
    }
  
    public class Car
    {
        public int ID { get; set; }
        public int ID2 { get; set; }
        public string Model { get; set; }
        public int Qty { get; set; }
        public decimal Price { get; set; }
  
        public Car(int id, int id2, string model, decimal price, int qty)
        {
            ID = id;
            ID2 = id2;
            Model = model;
            Qty = qty;
            Price = price;
        }
    }
  
    public class CarYear
    {
        public int ID { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public int Price { get; set; }
  
        public CarYear(int id, int year, string model, int price)
        {
            ID = id;
            Year = year;
            Model = model;
            Price = price;
        }
    }
  
}

Even though this is in C# (it's the quickest one I could come up with to get an answer to you) it should give you an idea to show that it can export, but only the top level rows.
Richard
0
Deepak
Top achievements
Rank 1
answered on 08 Feb 2011, 03:43 PM
Hi Richard,
 Thanks for your reply. Your code does not give me an error.However, I need to find a solution to export child templates on to excel. Infragistics supports it in a way by using the Display layout. I dont know why Telerik cannot find a solution. Microsoft not supporting does not carry support. At the very least, there should be a way of exporting the visual element, converting into HTML and exporting that to excel.

Thanks
Deepak
0
Richard Slade
Top achievements
Rank 2
answered on 08 Feb 2011, 03:52 PM
Hi Deepak,

Have a look at this forum thread.  I think it will help you
Richard
0
Deepak
Top achievements
Rank 1
answered on 10 Feb 2011, 11:34 AM
Thanks Richard, The thread doesnt really help me because it does not export the column definitions on to the spreadsheet. That is incredibly disheartening as the solution we are looking for needs to have the right column group headers on spreadsheets.
 I think we might also have a potential problem with printing if the column headers do not get printed.
0
Richard Slade
Top achievements
Rank 2
answered on 10 Feb 2011, 11:43 AM
Hi Deepak,

I'm sorry that this doesn't fulfill your requirements. I'll have a look as soon as I can to see if I can find any workaround, though this looks like quite a big one to try and solve. If I can come up with something that I think you would find useful, I'll let you know. In the meantime, I would suggest sending off a support ticket as a feature request (I haven't been able to find this in the Public Issue Tracking System).

Regards,
Richard
0
Deepak
Top achievements
Rank 1
answered on 10 Feb 2011, 11:53 AM
Thanks Richard,
    just sent a support ticket.
0
Martin Vasilev
Telerik team
answered on 11 Feb 2011, 01:55 PM
Hello Deepak,

I have answered already in your support ticket, but I am posting it here as well to be public available:

Curently we do not support exporting a RadGridView with ColumnGroupsViewDefinition or HtmlViewDefinition. We will consider adding this feature in one of the next releases.

As to the exporting hierarchical data, we are working on solution however I cannot give you a time-frame when it will be ready for release.

Greetings,
Martin Vasilev
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Nathaniel
Top achievements
Rank 1
answered on 23 Jun 2011, 08:39 PM
Looks like Telerik doesn't always get a chance to come back to these older threads. The ExportHierarchy feature is included in the latest release:

http://www.telerik.com/community/forums/winforms/gridview/excel-export-for-hierarchial-data-in-the-radgridview.aspx#1611645
0
Rahil
Top achievements
Rank 1
answered on 13 Dec 2011, 01:32 AM
Is the hierarchical export available in Telerik ASP.NET Ajax as well?  The link above seem to be relevant to WinForm version of RadGridView...

Thanks,
0
Stefan
Telerik team
answered on 15 Dec 2011, 05:02 PM
Hi Rahil,

This forum concerns RadControls for WinForms suite and not RadControls for ASP.NET AJAX. Please address your question in the appropriate forum, so you can get the answer to your question.
 
Best wishes,
Stefan
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Tags
GridView
Asked by
Deepak
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Deepak
Top achievements
Rank 1
Martin Vasilev
Telerik team
Nathaniel
Top achievements
Rank 1
Rahil
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or