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

Radgrid Export to Excel Style not applying for Empty Data

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Arun
Top achievements
Rank 1
Arun asked on 09 Apr 2014, 07:39 AM
Hi all,
I am trying to export empty data to excel.The style is not getting applied for Empty data or only Heading row.Please help
i have the below two eventhandlers to apply style:
 Protected Sub rgInbox_ExcelMLExportRowCreated(sender As Object, e As GridExcelBuilder.GridExportExcelMLRowCreatedArgs) Handles rgInbox.ExcelMLExportRowCreated
            If e.RowType = Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.HeaderRow Then
                For Index As Integer = 0 To e.Row.Cells.Count - 1
                    e.Row.Cells(Index).StyleValue = "normalHeaderStyle"
                Next

            End If
        End Sub

        Protected Sub rgInbox_ExcelMLExportStylesCreated(sender As Object, e As GridExcelBuilder.GridExportExcelMLStyleCreatedArgs) Handles rgInbox.ExcelMLExportStylesCreated
            Dim normalHeaderStyle As New GridExcelBuilder.StyleElement("normalHeaderStyle")
            normalHeaderStyle.FontStyle.Color = System.Drawing.Color.Black
            normalHeaderStyle.FontStyle.Bold = True
            normalHeaderStyle.FontStyle.FontName = "Calibri"
            normalHeaderStyle.FontStyle.Size = 10.0
            normalHeaderStyle.InteriorStyle.Pattern = GridExcelBuilder.InteriorPatternType.Solid
            normalHeaderStyle.InteriorStyle.Color = System.Drawing.Color.Gray
            e.Styles.Add(normalHeaderStyle)
        End Sub

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 11 Apr 2014, 01:02 PM
Hello Arun,

Thank you for contacting us.

The ExcelML format exports only the data in RadGrid. If there is no data an empty Excel sheet will be exported. In order to show the headers in the empty sheet you could use HTML or Biff export.

If you are using HTML export for example you could set the color of the header row in the exported file using code similar to the one below. It sets styles using the ItemCreated event of RadGird.

Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridHeaderItem Then
        e.Item.Style("background-color") = "#CCCCCC"
    End If
End Sub

Let me know if this approach is working for you.

Regards,
Viktor Tachev
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
Arun
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or