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

2 Radgrid exported to one excel sheet: issue is grey color patches are shown in exported excel

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 15 Apr 2010, 10:58 AM
I have 2 Radgrid ,1st Radgrid shows detail data with grouping and 2nd Radgrid shows total count ,i want to export data from both Radgrid to one excel file ,dataset for both Radgrid are different.

for this i have taken one another Parent Radgrid inside the div tag and above 2 Radgrids are inserted into the ItemTemplate column of
Parent RadGrid,data for both child Radgrid  binds on the Item_DataBound event of Parent Radgrid.Visibilty of div tag for Parnt Grid set to hidden.

I have used  "GridGroupByExpression" and " GridGroupByField" for grouping of 1st Child grid

Data successully bind to both child Radgrid and for export to excel i have used "RadGrid.MasterTableView.ExportToExcel()"syntax
Data for both child Radgrid shows in one excel file

but my issue is that after exporting  "grey colour patches"  are shown in excel sheet for 1child Radgrid with grouping .
due to which data is not properly visible and overlapped by the grey colur patches.please find the attached file "Report1.xls" for reference.

on removing the grouping "grey colour patches"  are not visible.

Any help or suggetion on  how to remove "grey colur patches " will be Grateful.

setting for Parent  Radgrid  OpenInNewWindow="True" IgnorePaging="True" ExportOnlyData = "false"

code snippet for Grouping:

GridGroupByExpression expression = new GridGroupByExpression();
            GridGroupByField gridGroupByField;

            gridGroupByField = new GridGroupByField();
            gridGroupByField.FieldName = ApplicationConstants.Reports.Name;
            gridGroupByField.HeaderText = "Report";
            gridGroupByField.HeaderValueSeparator = " : ";
            gridGroupByField.FormatString = "<strong>{0}</strong>";
            expression.SelectFields.Add(gridGroupByField);

         
            gridGroupByField = new GridGroupByField();
            gridGroupByField.FieldName = ApplicationConstants.Reports.Name;
            expression.GroupByFields.Add(gridGroupByField);



Code snippet for Export to excel:

            RadGrid.ExportSettings.OpenInNewWindow = true;
            RadGrid.Page.Response.ClearHeaders();
            RadGrid.Page.Response.Cache.SetCacheability(HttpCacheability.Private);

            RadGrid.ExportSettings.ExportOnlyData = false;
            RadGrid.ExportSettings.Excel.Format = GridExcelExportFormat.Html;
            RadGrid.MasterTableView.ExportToExcel();


   Environment details:

   Asp.Net  3.5 version
  OS : Windows server 2003
  Internet explorer : ie 6.0







1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 21 Apr 2010, 12:23 PM
Hello Ram,

You can remove the unwanted controls/items manually.
bool isExport = false;
 
protected void Button1_Click(object sender, EventArgs e)
{
    isExport = true;
    RadGrid1.Rebind();
    RadGrid1.MasterTableView.ExportToExcel();
}

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (isExport == true)
        RemoveControls(e.Item);
}

Simple recursive method that will remove all controls/items - you can customize it as suitable for your scenario
public void RemoveControls(Control ctrl)
{
    var q = new Stack<Control>(ctrl.Controls.OfType<Control>());
    while (q.Count > 0)
    {
        Control control = q.Pop();
 
        if (control is IButtonControl || control is ICheckBoxControl || control is ITextControl || control is GridPagerItem || control is GridFilteringItem)
            ctrl.Controls.Remove(control);
        if (control.HasControls())
            RemoveControls(control);
    }
}

I hope this helps.

Regards,
Daniel
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.
Tags
Grid
Asked by
Ram
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or