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

Formatting not applied when exporting to excel

1 Answer 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 07 Aug 2013, 05:31 PM
Hi

I am using an old version of RadGrid (2008 Q3) but I hope you will still be able to help.

None of the styles in the grid's skin are applied when I export to excel. They are not applied if i use an embedded skin or a custom skin.
I tried adding styles manually as shown in the documentation like so:

Protected Sub gridJourneys_ExcelMLExportStylesCreated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs) Handles gridJourneys.ExcelMLExportStylesCreated
       For Each style As Telerik.Web.UI.GridExcelBuilder.StyleElement In e.Styles
           If style.Id = "headerStyle" Then
               style.FontStyle.Bold = True
               style.FontStyle.Color = System.Drawing.Color.Gainsboro
               style.InteriorStyle.Color = System.Drawing.Color.Wheat
               style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid
           ElseIf style.Id = "itemStyle" Then
               style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke
               style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid
           ElseIf style.Id = "alternatingItemStyle" Then
               style.InteriorStyle.Color = System.Drawing.Color.LightGray
               style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid
           End If
       Next
      
   End Sub

i have tried this with an embedded skin and a custom skin and the styles are not applied to the excel doc

This does work though

Protected Sub gridJourneys_ExcelExportCellFormatting(ByVal source As Object, ByVal e As Telerik.Web.UI.ExcelExportCellFormattingEventArgs) Handles gridJourneys.ExcelExportCellFormatting
     If e.FormattedColumn.UniqueName = "StartLocation" Then
         
         e.Cell.Style("color") = "red"
 
 
 
     End If
     If e.FormattedColumn.UniqueName = "ExpandColumn" Then
         e.Cell.Controls.Clear()
     End If
  
 End Sub


How do i get the styles from the stylesheet to be applied in the excel document

thanks a lot

1 Answer, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 12 Aug 2013, 09:03 AM
Hi Andieje,

I am not completely sure which excel format you are using Html or ExcelML. Note that if you are using Html based format ExcelMLExportStylesCreated event handler will not be fired and therefore if you are using ExcelML ExcelExportCellFormatting will not be fired. I prepared a small sample where I demonstrates how to style the exported grid in both cases and attached it to this forum post.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or