export to excel without a radgrid

8 posts, 0 answers
  1. Abhinav
    Abhinav avatar
    2 posts
    Member since:
    Mar 2012

    Posted 19 Mar 2012 Link to this post

    hi all,
               i have a requirement in which i have to export data to an excel when a certain conditions are given without displaying the data in a radgrid , i have tried making radgrid invisible but the data is not exporting when grid is invisible ...........help is much appreciated.
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 20 Mar 2012 Link to this post

    Hi Abhinav,

    Thank you for writing.

    Here is a code snippet which demonstrates how to achieve this:
    using (RadGridView grid = new RadGridView())
    {
        grid.Visible = false;
        this.Controls.Add(grid);
        grid.Size = new Size(800, 600);
        grid.AutoGenerateColumns = true;
        grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
        DataTable table = new DataTable();
        for (int i = 0; i < 5; i++)
        {
            table.Columns.Add("Column " + i);
        }
     
        for (int i = 0; i < 20; i++)
        {
            table.Rows.Add(i, i, i, i, i);
        }
     
        grid.DataSource = table;
        grid.LoadElementTree();
     
        ExportToExcelML export = new ExportToExcelML(grid);
        string fileName = @"C:\grid.xls";
        export.RunExport(fileName);
        this.Controls.Remove(grid);
    }
    The obligatory steps here are that you have to specify a size for the grid, you have to add it to the controls collection of a form, set a data source and call LoadElementTree method.

    I hope this will be useful for you. Should you have further questions I would be glad to assist.

    All the best,
    Ivan Petrov
    the Telerik team

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

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Abhinav
    Abhinav avatar
    2 posts
    Member since:
    Mar 2012

    Posted 20 Mar 2012 Link to this post

    thanks Ivan Petrov , i have solved it by putting the grid in a div and not showing in client side.

    i.e     divID.style["Display"]="none";   that should do the trick .............:)
  5. Vikram
    Vikram avatar
    5 posts
    Member since:
    Sep 2012

    Posted 11 Sep 2012 Link to this post

    Dim grid As RadGridView = New RadGridView
    grid.Visible = False
    grid.DataSource = TCBdayDataAccess.GetTCBdayInformation()
    grid.LoadElementTree()
     
    Dim export As New ExportToExcelML(grid)
    Dim fileName As String = "C:\grid.xls"
    export.RunExport(fileName)
    I am using the above mentioned code but I get an exception  at the last line of the code "Unable to cast object of type 'Telerik.WinControls.UI.GroupPanelElement' to type 'Telerik.WinControls.RadElement'."

    Any suggestions?
  6. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 14 Sep 2012 Link to this post

    Hi Vikram,

    Thank you for writing.

    Can you please verify that you have a reference to the TelerikData assembly in your project? Also, can you check whether all your references point to the same version of the Telerik assemblies? If this does not help, I would kindly ask you to open a support ticket and send your project so we can investigate the issue further.

    I hope this will help. If you have other questions, do not hesitate to write back.

    Greetings,
    Ivan Petrov
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  7. Kevin
    Kevin avatar
    1 posts
    Member since:
    Mar 2013

    Posted 01 Mar 2013 Link to this post

    Thank you so much, Ivan for this code!  I've been at war with my Excel tables all week and have had an especially difficult go of it with radgrid and other interface issues.  Works like a charm now.  :)
  8. Behnam
    Behnam avatar
    1 posts
    Member since:
    Jul 2014

    Posted 15 Jul 2014 Link to this post

    Unable to cast object of type 'Telerik.WinControls.UI.GroupPanelElement' to type 'Telerik.WinControls.RadElement'.
    error occord when i tried to export grid to excel. i do every thing that the programer suggest but not work.
    my code is

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls;
    using System.Data.SqlClient;
    using BehComponents;
    using Telerik.WinControls.UI;
    using Telerik.WinControls.UI.Export;
    using Telerik.WinControls.Data;

     ExportToExcelML exporter = new ExportToExcelML(GEmpGrp);
                    exporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport;
                    exporter.ExportVisualSettings = true;
                    exporter.SummariesExportOption = SummariesOption.DoNotExport;
                    string fileName = @"C:\grid.xls";
                    exporter.RunExport(fileName);
  9. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 18 Jul 2014 Link to this post

    Hi Behnam,

    Thank you for writing.

    Despite my efforts, I was unable to reproduce such an exception on my end. In order to allow us to investigatethis case, please get back to us with a  sample project where the issue can be reproduced. 

    Having in mind that the forums does not allow zip attachments and in order to avoid mixing different subject in one forum thread, I would kindly ask you to open a support ticket and provide your project there. 

    Thank you in advance for your time and cooperation.

    Kind regards,
    Stefan
    the Telerik team
     

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready