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

[Solved] Export to Excel

10 Answers 246 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Josip Jaic
Top achievements
Rank 2
Josip Jaic asked on 12 Oct 2010, 02:13 PM
Hi,

I have upgraded versions of SL4 and Telerik controls (to latest), and grids feature export to Excel stopped working.
grid is fully loaded and displayed ok when i press button for export
i am using this code, and exception is at the bottom (fired on line rgvZadaci.Export(stream, exportOptions);)

is this known bug? or I am doing something wrong?

 SaveFileDialog dialog = new SaveFileDialog ( )
            {
                DefaultExt = "xls",
                Filter = String.Format ( "{1} files (*.{0})|*.{0}|All files (*.*)|*.*""xls""Excel" ),
                FilterIndex = 1
            };

            if ( dialog.ShowDialog ( ) == true )
            {
                using ( Stream stream = dialog.OpenFile ( ) )
                {


                    try
                    {
                        GridViewExportOptions exportOptions = new GridViewExportOptions();
                        exportOptions.Format = ExportFormat.ExcelML;
                        exportOptions.ShowColumnFooters = false;
                        exportOptions.ShowColumnHeaders = true;
                        exportOptions.ShowGroupFooters = false;

                        rgvZadaci.Export(stream, exportOptions);

                     
                    }
                    catch (Exception ex)
                    {
                        LoggerHelper.Log(LogType.error, "Unable to generate excel "+ex.Message,ex.StackTrace );
                        return;
                    }                  
                }
            }




   u Telerik.Windows.Data.TypeExtensions.DefaultValue(Type type)
   u Telerik.Windows.Data.Expressions.ExpressionFactory.DefaltValueExpression(Type type)
   u Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Type memberType)
   u Telerik.Windows.Data.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Type memberType, Boolean liftMemberAccessToNull)
   u Telerik.Windows.Data.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpressionOverride()
   u Telerik.Windows.Data.Expressions.MemberAccessExpressionBuilderBase.CreateMemberAccessExpression()
   u Telerik.Windows.Data.Expressions.MemberAccessExpressionBuilderBase.CreateLambdaExpression()
   u Telerik.Windows.Data.BindingToExpressionExtensions.CreateMemberAccessLambdaExpression(Binding binding, Type objectType, Type memberType)
   u Telerik.Windows.Data.BindingToExpressionExtensions.CreateUntypedMemberAccessFunc(Binding binding, Type objectType, Type memberType)
   u Telerik.Windows.Data.BindingToExpressionExtensions.CreateMemberAccessFunc(Binding binding, Type objectType, Type memberType)
   u Telerik.Windows.Data.DataFieldDescriptorExtensions.CreateMemberAccessFunc(IDataFieldDescriptor fieldDescriptor)
   u Telerik.Windows.Controls.GridViewBoundColumnBase.InitializeMemberAccessFunc()
   u Telerik.Windows.Controls.GridViewBoundColumnBase.get_MemberAccessFunc()
   u Telerik.Windows.Controls.GridViewBoundColumnBase.GetCellContent(Object item)
   u Telerik.Windows.Controls.GridViewExportWriter.RenderDataCells(Object item)
   u Telerik.Windows.Controls.GridViewExportWriter.RenderDataRows(IEnumerable items)
   u Telerik.Windows.Controls.GridViewExportWriter.Render()
   u Telerik.Windows.Controls.GridView.GridViewDataControl.Export(Stream stream, GridViewExportOptions options)
   u RMSSilverlight.ZadaciView.btnZadatakExportXLS_Click(Object sender, RoutedEventArgs e)

10 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 14 Oct 2010, 12:49 PM
Hi Josip Jaic,

 I'm sorry, but without looking at your whole application (specifically, the data types), we're unable to debug this exception.

Regards,
Yavor Georgiev
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
Josip Jaic
Top achievements
Rank 2
answered on 24 Oct 2010, 09:52 PM
Hi Yavor,

I figured it out,
problem was because i have button in my first column. When i commedted it out it worked ok. (export to excel)
But in previous version of Telerik Grid i had same code, and export worked ok.
Should i use some other way to have button in grid?
tnx
this is button column I use

 

 

 

<telerikGridView:GridViewDataColumn UniqueName="rgvZadaci_dc_Detalji" Header="Detalji">

 

 

 

 

<telerikGridView:GridViewDataColumn.CellTemplate>

 

 

 

 

<DataTemplate>

 

 

 

 

<Button Content="Detalji" x:Name="btnZadaciDetalji" Click="btnZadaciDetalji_Click" Style="{StaticResource GridViewButtonStyle}"/>

 

 

 

 

</DataTemplate>

 

 

 

 

</telerikGridView:GridViewDataColumn.CellTemplate>

 

 

 

 

</telerikGridView:GridViewDataColumn>

 

0
Yavor Georgiev
Telerik team
answered on 25 Oct 2010, 11:12 AM
Hello Josip Jaic,

 You can handle the ElementExporting event of RadGridView and cancel it if the element about to be exported is a cell of that column.

Sincerely yours,
Yavor Georgiev
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
Josip Jaic
Top achievements
Rank 2
answered on 25 Oct 2010, 04:42 PM
Hi,

I tried to cancel in ElementExporting event, but as i can see (picture)
element who is exporting is row. And each row has one Entity from my context.
So I was unable to e.Cancel=true; special column.

But doing this (my first column has button)
rgvZadaci.Columns[0].IsVisible = false;
rgvZadaci.Export(stream, exportOptions);
rgvZadaci.Columns[0].IsVisible = true;



That did the trick :)

Now i noticed that only first page (i have datapager) is exported in Excel..
Application has option to increase page size... (workaround)
0
Yavor Georgiev
Telerik team
answered on 25 Oct 2010, 04:54 PM
Hello Josip Jaic,

 Please check out this demo.

All the best,
Yavor Georgiev
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
Josip Jaic
Top achievements
Rank 2
answered on 25 Oct 2010, 05:04 PM

Hi,

that was quick :) Thank you.

 

it works ok now.

Here is my code (two data pagers):

                        int originalPageSize = dpZadaciUp.PageSize;
                        int originalPageIndex = dpZadaciUp.PageIndex;
                        dpZadaciUp.PageSize = 0;
                        dpZadaciDown.PageSize = 0;

                        GridViewExportOptions exportOptions = new GridViewExportOptions();
                        exportOptions.Format = ExportFormat.ExcelML;
                        exportOptions.ShowColumnFooters = false;
                        exportOptions.ShowColumnHeaders = true;
                        exportOptions.ShowGroupFooters = false;
                     

                        rgvZadaci.Columns[0].IsVisible = false;

                        rgvZadaci.Export(stream, exportOptions);

                        rgvZadaci.Columns[0].IsVisible = true;

                        dpZadaciUp.PageSize = originalPageSize;
                        dpZadaciDown.PageSize = originalPageSize;
                        dpZadaciUp.PageIndex = originalPageIndex;
0
Yavor Georgiev
Telerik team
answered on 25 Oct 2010, 05:10 PM
Hello Josip Jaic,

 You don't need to modify the PageSize and PageIndex properties of your pagers, you just need to set the Items property of the GridViewExportOptions object to your actual data source (what your pagers are bound to).

Sincerely yours,
Yavor Georgiev
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
Spartan IV
Top achievements
Rank 1
answered on 19 Jan 2011, 09:19 AM
I have some thousands of records and a pager. If i set the Items = pager.Source and I have a grouping by country for example, all data is exported but the grouping is lost even with the Q3 2010

I want to export all data, have a pager and have column groupings. When you set the Items to something the rest of the GridViewExportOptions are ignored, or is there a way?

Setting the PageSize to 0 is not an option,because there is so much data, that locks the Silverlight app. What should I do?
0
Yavor Georgiev
Telerik team
answered on 20 Jan 2011, 01:10 PM
Hello Josip Jaic,

 Create a new QueryableCollectionView from your original data source, copy all the GroupDescriptors from your RadGridView to the new QueryableCollectionView. and then set the Items property of GridViewExportOptions to the View.

Greetings,
Yavor Georgiev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Josip Jaic
Top achievements
Rank 2
answered on 20 Jan 2011, 01:52 PM

Hi,

My problem was solved on Oct 24, 2010

Tags
GridView
Asked by
Josip Jaic
Top achievements
Rank 2
Answers by
Yavor Georgiev
Telerik team
Josip Jaic
Top achievements
Rank 2
Spartan IV
Top achievements
Rank 1
Share this question
or