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

export to excel without a radgrid

7 Answers 478 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Abhinav
Top achievements
Rank 1
Abhinav asked on 20 Mar 2012, 02:52 AM
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.

7 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 20 Mar 2012, 01:40 PM
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 >>

0
Abhinav
Top achievements
Rank 1
answered on 20 Mar 2012, 03:16 PM
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 .............:)
0
Vikram
Top achievements
Rank 1
answered on 11 Sep 2012, 04:53 PM
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?
0
Ivan Petrov
Telerik team
answered on 14 Sep 2012, 01:29 PM
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.

0
Kevin
Top achievements
Rank 1
answered on 01 Mar 2013, 08:42 PM
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.  :)
0
Behnam
Top achievements
Rank 1
answered on 15 Jul 2014, 07:27 PM
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);
0
Stefan
Telerik team
answered on 18 Jul 2014, 08:49 AM
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.

 
Tags
GridView
Asked by
Abhinav
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Abhinav
Top achievements
Rank 1
Vikram
Top achievements
Rank 1
Kevin
Top achievements
Rank 1
Behnam
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or