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

Exporting gridview to Excel,Word or CSV

6 Answers 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
naresh
Top achievements
Rank 1
naresh asked on 16 Jun 2011, 12:58 PM
Hi
I am experiencing some problem.While exporting columns of Radgridview to excel or other supported native formats...some columns are not exporting.
for those columns set the property 
IsVisible="False"
in xaml file.
so I have 2 doubts..
1)How to export all columns which are bind to grid irrespective of visibility.
2)I have a Ilist which is datasource of gribView.is it possible to export those list to different files ?

the following was sample code...
using (Stream stream = dialog.OpenFile())
{
GridViewExportOptions exportOptions = new GridViewExportOptions();
exportOptions.Format = format;
exportOptions.ShowColumnFooters = true;
exportOptions.ShowColumnHeaders = true;
grdView.Export(stream, exportOptions);
}
Regards Naresh

6 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 16 Jun 2011, 03:29 PM
Hello naresh,

I have prepared an example project that handles such a scenario. Please, refer to it and let me know if this approach meets your requirements.

Greetings,
Ivan Ivanov
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
naresh
Top achievements
Rank 1
answered on 16 Jun 2011, 04:00 PM
Before posting I tried with that answer...its working..some how i am not satisfied..Hope next update there is option in export options.

please solve my second problem.that is how to export Gridview data source to different formats......
0
Ivan Ivanov
Telerik team
answered on 20 Jun 2011, 09:27 AM
Hello naresh,

This is the recommended approach for exporting hidden columns and modifying it may result into introducing a breaking change in the exporting feature's implementation. Would you please share with us why this approach doesn't meet your requirements, so that we could think of another solution for your case? As for the second question, would you please shed some more light on your requirements? Do you want to show a SaveFileDialog for each of the files and if not where do you intend to save them? A little more info on these points would be highly appreciated.

All the best,
Ivan Ivanov
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
naresh
Top achievements
Rank 1
answered on 21 Jun 2011, 08:00 AM
Hello Ivan Ivanov,
 Thanks for your post.
According to your approach I found some problem. off-course its not a big problem.Problem is that if I have a large amount of data populated in gridview while changing visible status of columns would lead to some display problem.means expanding columns and collapsing columns looks odd for clients.while making visible true for hidden columns i am changing column width to 0. 

My second requirement is I am using MVVM pattern.so I am assigning item source as binding List.if i want to export that list to different formats is there any approach available.

few doubts
1) Is there any way to export few columns depends on requirements(Not above approach changing visible status of columns)
If not there.. hope u people can include that feature in next update.(Just passing collection of columns to export options)
2) If I don't want to show save dialogue is there any way..(off course I will give static path) 

Thanks and Regards
Naresh Mesineni
0
Ivan Ivanov
Telerik team
answered on 21 Jun 2011, 03:14 PM
Hello naresh,

I have prepared an example project that exports a RadGridView, in all the possible format, in your local user's Documents folder.  As for the first point of "few doubts", users can easily cancel the exporting of unwanted elements on the  ElementExporting event, so passing a collection of columns would be quite unnecessary.  Please, refer to the attached project.

Greetings,
Ivan Ivanov
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
Usman
Top achievements
Rank 1
answered on 22 Mar 2012, 09:02 AM
hi there,

when i use your sample project code to export my radgridview data to excel it works BUT when i open that exported excel the the microsoft excel gives an error which is "The File you are trying to open A.xls is in different format then specified by the file extension. Verify that the file is corrupted and is from a trusted source before opening the file. Do you want to open the file? "

the code for this is:

i prefer to hav the sample project thnx :)

Tags
GridView
Asked by
naresh
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
naresh
Top achievements
Rank 1
Usman
Top achievements
Rank 1
Share this question
or