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

Exporting and grid style

1 Answer 38 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marius du Toit
Top achievements
Rank 1
Marius du Toit asked on 02 Jun 2010, 08:32 PM
Is it possible to export cell styles like background, font, etc? I would like to refer to the style currently applied for a cell and carry that forward for the export to Excel. I would like to get a WYSIWYG export of the grid to Excel.

For instance,

 

 

If (e.Element = ExportElement.HeaderRow) Then

 

    e.Background = radGridView.HeaderRowStyle.GetValue(<BackgroundProperty of the style applied for header row>)

 

End If

Being able to do this will eliminate duplicate style, one for the UI and one for the export. Since the grid is styled in XAML, none of the colors etc is currently available in code (unless I can retrive it programmatically via code).

Thanks.

 

 

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 04 Jun 2010, 01:21 PM
Hi Marius du Toit,

You need to subscribe to the Exporting event (or to ElementExporting event which we introduced in Q1 2010 SP2 release) and use the following code:


private void gridView_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
    if (e.Element == ExportElement.HeaderRow)
    {
        GridViewHeaderRow hr = e.Context as GridViewHeaderRow;
 
        e.Background = ((LinearGradientBrush)(hr.Background)).GradientStops[0].Color ;
    }
}

Greetings,
Veskoni
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
GridView
Asked by
Marius du Toit
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or