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

Unable to export Excel in RadGrid

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vishnu
Top achievements
Rank 1
Vishnu asked on 03 Mar 2015, 08:04 AM
Hi, I am trying to export Excel from RadGrid control, but its giving page error. Unable to debug also. Immediately its expires the page. I have used <GroupByExpressions> option in grid. Is this not allowing us to export excel ?
Because I didn't find any demos or example in from your end on export excel with <GroupByExpressions> option.

In the code behind C# code - 
buttonexport click event i have written below code

Grid.ExportSettings.IgnorePaging = true;
Grid.ExportSettings.ExportOnlyData = true;
Grid.ExportSettings.OpenInNewWindow = true;
Grid.ExportSettings.FileName = "filename";
  
Grid.MasterTableView.ExportToExcel();


if you mentioned below line before exporting method. Getting page error - 

Grid.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;

below is the apx code - 
<telerik:RadGrid
               ShowGroupPanel          ="false"
               AutoGenerateColumns     ="false"
               ID                      ="Grid"
               AllowFilteringByColumn  ="False"
               AllowSorting            ="False"
               ShowFooter              ="True"
               runat                   ="server"
               GridLines               ="Both"
               AllowPaging             ="false"
               EnableLinqExpressions   ="false"
               CssClass                ="RadGridCustomClass"
               OnPreRender             ="Grid_PreRender"
               OnExcelMLExportRowCreated="Grid_ExcelMLExportRowCreated"
               OnGridExporting         ="Grid_GridExporting"
               OnExcelMLExportStylesCreated="Grid_ExcelMLExportStylesCreated"
               OnItemDataBound         ="Grid_ItemDataBound">
               <PagerStyle Mode="NextPrevAndNumeric" />
               <MasterTableView
                   ShowGroupFooter         ="true"
                   HeaderStyle-Font-Bold   ="true"
                   HeaderStyle-ForeColor   ="#333333"
                   AllowMultiColumnSorting ="false">
                   <Columns>
                       <telerik:GridBoundColumn
                           DataField                   ="SubCategory"
                           ItemStyle-HorizontalAlign   ="Center"
                           UniqueName                  ="REP013_FuellingCategoryHeaderText"
                           FooterStyle-HorizontalAlign ="Center"
                           FooterStyle-Font-Bold       ="true"
                           HeaderStyle-HorizontalAlign ="Center" >
                       </telerik:GridBoundColumn>
                         
                       <telerik:GridBoundColumn
                           Aggregate                   ="Sum"
                           DataField                   ="Total_Fuel_Litres"
                           DataType                    ="System.Int32"
                           UniqueName                  ="REP013_TotalFuelHeaderText"
                           DataFormatString            ="{0:###,###.##}"
                           ItemStyle-HorizontalAlign   ="Center"
                           FooterStyle-HorizontalAlign ="Center"
                           FooterStyle-Font-Bold       ="true"
                           HeaderStyle-HorizontalAlign ="Center"
                           FooterText                  ="<%$ Resources:MyGlobals, REP013_TotalFuelFooterText%>">
                       </telerik:GridBoundColumn>
                         
                       <telerik:GridBoundColumn
                           Aggregate                   ="Avg"
                           DataField                   ="Bio_Content"
                           DataFormatString            ="{0:0.0%}"
                           UniqueName                  ="REP013_BioContentHeaderText"
                           ItemStyle-HorizontalAlign   ="Center"
                           FooterStyle-HorizontalAlign ="Center"
                           FooterStyle-Font-Bold       ="true"
                           HeaderStyle-HorizontalAlign ="Center" >
                       </telerik:GridBoundColumn>
                         
                       <telerik:GridBoundColumn
                           Aggregate                   ="Sum"
                           DataField                   ="Bio_Diesel_Litres"
                           DataFormatString            ="{0:###,###}"
                           UniqueName                  ="REP013_BioDieselHeaderText"
                           ItemStyle-HorizontalAlign   ="Center"
                           FooterStyle-HorizontalAlign ="Center"
                           FooterStyle-Font-Bold       ="true"
                           HeaderStyle-HorizontalAlign ="Center"
                           FooterText                  ="<%$ Resources:MyGlobals, REP013_BioDieselFooterText%>">
                       </telerik:GridBoundColumn>
                         
                       <telerik:GridBoundColumn
                           Aggregate                   ="Sum"
                           DataField                   ="Standard_Diesel_Litres"
                           DataFormatString            ="{0:###,###}"
                           UniqueName                  ="REP013_StandardDieselHeaderText"
                           ItemStyle-HorizontalAlign   ="Center"
                           FooterStyle-HorizontalAlign ="Center"
                           FooterStyle-Font-Bold       ="true"
                           HeaderStyle-HorizontalAlign ="Center"
                           FooterText                  ="<%$ Resources:MyGlobals, REP013_StandardDieselFooterText%>">
                       </telerik:GridBoundColumn>
                         
                       <telerik:GridBoundColumn
                           Aggregate                   ="Sum"
                           DataField                   ="CO2_Tonnes"
                           DataFormatString            ="{0:###,##0.0}"
                           UniqueName                  ="REP013_CO2QuantityHeaderText"
                           ItemStyle-HorizontalAlign   ="Center"
                           FooterStyle-HorizontalAlign ="Center"
                           FooterStyle-Font-Bold       ="true"
                           HeaderStyle-HorizontalAlign ="Center"
                           FooterText                  ="<%$ Resources:MyGlobals, REP013_CO2QuantityFooterText%>">
                       </telerik:GridBoundColumn>
                   </Columns>
                   <GroupByExpressions>
                       <telerik:GridGroupByExpression>
                           <SelectFields>
                               <telerik:GridGroupByField FieldName="Category" />
                           </SelectFields>
                           <GroupByFields>
                               <telerik:GridGroupByField FieldName="Category" SortOrder="Ascending" />
                           </GroupByFields>
                       </telerik:GridGroupByExpression>
                   </GroupByExpressions>
               </MasterTableView>
               <ClientSettings AllowDragToGroup    ="false" />
               <GroupingSettings ShowUnGroupButton ="false" />
           </telerik:RadGrid>


Can you please help out, how to export excel when we have <GroupByExpressions> option on aspx page.
Let me know if you need any more information.


for the reference I have added snapshots





1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 03 Mar 2015, 04:36 PM
Hello Vishnu,

I'm afraid the problem does not reproduce. I have attached a runnable demo to the support ticket.
When we find a solution we can post it here so that I can be available for the community.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Vishnu
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or