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

Pass value into ExcelTableCreated sub

2 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 30 Apr 2013, 12:39 AM
I've read through the examples and forums and can't find an answer.  In the code below you can see that a new row is added to the spreadsheet showing the "Exported" time and date.  It is also formatted.  That works fine.

What I want to do is pass a string into the sub that can be used in the AddCustomExcelRow to describe the contents of the grid that is being exported.  Assume I have a grid showing "Top Investments".  I would like to pass that string into the sub below and use it as a new row.  I would want to pass a descriptive string from any grid I choose.  Any ideas?


Public Sub exporter_ExcelTableCreated(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.Export.ExcelML.ExcelTableCreatedEventArgs)
 
    Dim subHeader As String = "Exported " & Now().ToString
    Dim style1 As ExcelML.SingleStyleElement = (CType(sender, ExportToExcelML)).AddCustomExcelRow(e.ExcelTableElement, 0, subHeader)
    style.FontStyle.Bold = True
    style.FontStyle.Size = 11
    style1.FontStyle.Color = Color.RoyalBlue

2 Answers, 1 is accepted

Sort by
0
Accepted
Svett
Telerik team
answered on 02 May 2013, 01:48 PM
Hello Brendan,

You can achieve that by extending the ExportToExcelML class in the following manner:
Public Class MyExportToExcelML
    Inherits ExportToExcelML
    Private m_caption As String
 
    Public Sub New(grid As RadGridView)
 
        MyBase.New(grid)
    End Sub
 
    Public Property Caption() As String
        Get
            Return Me.m_caption
        End Get
        Set
            Me.m_caption = value
        End Set
    End Property
End Class

Then you can use the class in the following manner:
Dim impl As New MyExportToExcelML(Me.radGridView1)
impl.Caption = "Your caption"
AddHandler impl.ExcelTableCreated, AddressOf impl_ExcelTableCreated
impl.RunExport("C:\\test.xlx")

Private Sub impl_ExcelTableCreated(sender As Object, e As Telerik.WinControls.UI.Export.ExcelML.ExcelTableCreatedEventArgs)
    Dim exporter As MyExportToExcelML = TryCast(sender, MyExportToExcelML)
    Dim subHeader As String = exporter.Caption
    Dim style As SingleStyleElement = DirectCast(sender, ExportToExcelML).AddCustomExcelRow(e.ExcelTableElement, 0, subHeader)
    style.FontStyle.Bold = True
    style.FontStyle.Size = 11
    style.FontStyle.Color = Color.RoyalBlue
End Sub

I hope that you find this information useful.

Kind regards,
Svett
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
Brendan
Top achievements
Rank 1
answered on 02 May 2013, 05:27 PM
Thanks so much Svett.  That worked perfectly.  In case anyone is interested I found you can also add a border in the ExcelTableCreated event;

'add header row
Dim sHeader As String = exporter.Caption
 
'set header caption
Dim style1 As ExcelML.SingleStyleElement = DirectCast(sender, ExportToExcelML).AddCustomExcelRow(e.ExcelTableElement, 0, sHeader)
With style1
    .FontStyle.Bold = True
    .FontStyle.Size = 14
    .FontStyle.Color = Color.Blue
    .InteriorStyle.Color = Color.FromArgb(240, 240, 240)
    .InteriorStyle.Pattern = ExcelML.InteriorPatternType.Solid
End With
 
'add subheader row
Dim subHeader As String = "Exported " & Now().ToString
Dim style2 As ExcelML.SingleStyleElement = (CType(sender, ExportToExcelML)).AddCustomExcelRow(e.ExcelTableElement, 0, subHeader)
 
'create border, add to row
Dim border As ExcelML.BorderStyles = New ExcelML.BorderStyles()
border.Color = Color.Black
border.Weight = 1
border.LineStyle = ExcelML.LineStyle.Continuous
border.PositionType = ExcelML.PositionType.Bottom
With style2
    .FontStyle.Bold = True
    .InteriorStyle.Color = Color.FromArgb(240, 240, 240)
    .InteriorStyle.Pattern = ExcelML.InteriorPatternType.Solid
    .Borders.Add(border)
End With
Tags
GridView
Asked by
Brendan
Top achievements
Rank 1
Answers by
Svett
Telerik team
Brendan
Top achievements
Rank 1
Share this question
or