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

Add style for new added Row in exporting to Excel

2 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 25 Feb 2011, 11:07 PM
Hi all, 

The footer is not added by using ExcelML. Therefore, I have to do some coding in ExcelMLExportRowCreated.
Dim row As New RowElement()  is use for adding footer.
Everything is good.
But I would like to change its style, something like border, color, background color.
Need a hellp from all of you.

Andy.

Protected Sub carGrid_ExcelMLExportRowCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs) Handles carGrid.ExcelMLExportRowCreated
       If e.Worksheet.Table.Rows.Count = carGrid.Items.Count + 1 Then
           Dim row As New RowElement()
           Dim footer As GridFooterItem = TryCast(TryCast(sender, RadGrid).MasterTableView.GetItems(GridItemType.Footer)(0), GridFooterItem)
           For Each column As GridColumn In TryCast(sender, RadGrid).MasterTableView.Columns
               Dim cell As New CellElement()
               Dim cellText As String = footer(column.UniqueName).Text
               Dim result As Integer
               If cellText.Contains(" ") Then
                   Try
                       result = Integer.Parse(cellText.Substring(6, cellText.Length - 6))
                       cell.Data.DataItem = result
                   Catch ex As Exception
                       Exit Sub
                   End Try
               ElseIf cellText = "0" Then
                   cell.Data.DataItem = 0
               Else
                   cell.Data.DataItem = cellText
               End If
               row.Cells.Add(cell)
           Next       
           e.Worksheet.Table.Rows.Add(row)
       End If
        
   End Sub

2 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 28 Feb 2011, 11:50 PM
Could anyone help me on this problem?
0
Daniel
Telerik team
answered on 02 Mar 2011, 04:37 PM
Hello Andy,

1) Create your own style:
Copy Code
Protected Sub RadGrid1_ExcelMLExportStylesCreated(source As Object, e As GridExportExcelMLStyleCreatedArgs) Handles RadGrid1.ExcelMLExportStylesCreated
    Dim myStyle As New StyleElement("MyStyle")
    myStyle.FontStyle.Bold = True
    e.Styles.Add(myStyle)
End Sub

2) Set your custom style ID to footer item's cells:
Copy Code
        cell.Data.DataItem = cellText
    End If
    cell.StyleValue = "MyStyle"
    row.Cells.Add(cell)
Next     
e.Worksheet.Table.Rows.Add(row)

For more information, please visit the following link:
ExcelML basics

Regards,
Daniel
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or