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

[Solved] Export Excel - Grid - repeat group rows of data

1 Answer 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danka
Top achievements
Rank 1
Danka asked on 03 Jul 2014, 08:28 PM
Hi there:

I need to export to Excel with no grouping but I would like to repeat a group data for  each row.  For example

My on screen report
Group A:  12345
      Data1    Data2   Data3
      Data4     Data    Data 6

I would like the output in excel as follows
12345  Data1 Data2 Data2
12345  Data4 Data5 Data6

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Jul 2014, 05:06 AM
Hi Danka,

To obtain your requirement, you can hide the Grouping column and on export you can set that columns display to True then hide the GroupHeaderText on export. Take a look at the below code snippet.

ASPX:
<telerik:RadGrid ID="rgClassGrid" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnItemCommand="rgClassGrid_ItemCommand" OnPreRender="rgClassGrid_PreRender">
    <ExportSettings ExportOnlyData="true">
    </ExportSettings>
    <MasterTableView CommandItemDisplay="Top">
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="ShipCountry" HeaderText="ShipCountry" />
                </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="ShipCountry" SortOrder="Descending" />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
        <CommandItemSettings ShowExportToExcelButton="true" />
        <Columns>
            <telerik:GridBoundColumn UniqueName="ShipCountry" DataField="ShipCountry" Display="false" />
            <telerik:GridBoundColumn UniqueName="ShipCity" HeaderText="ShipCity" DataField="ShipCity" />
            <telerik:GridBoundColumn UniqueName="Freight" HeaderText="Freight" DataField="Freight" />
            <telerik:GridBoundColumn UniqueName="ShipVia" HeaderText="ShipVia" DataField="ShipVia" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void rgClassGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        isExport = true;
        rgClassGrid.MasterTableView.GetColumn("ShipCountry").Display = true;
    }
}  
protected void rgClassGrid_PreRender(object sender, EventArgs e)
{
    if (isExport)
    {
    foreach (GridGroupHeaderItem groupHeader in rgClassGrid.MasterTableView.GetItems(GridItemType.GroupHeader))
      {
         groupHeader.DataCell.Text = string.Empty;
      }
    }
}

Thanks,
Shinu
Tags
Grid
Asked by
Danka
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or