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

Export to Excel - Using cell's value member

6 Answers 92 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Johan
Top achievements
Rank 1
Johan asked on 07 Feb 2011, 05:42 PM
Hi,

Is it possible to export a cell's value member instead of the display member when exporting to excel using ExportToExcelML?

Thanks

6 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 06:13 PM
Hi Ryno,

You should be able to do this I believe with the ExcelCellFormatting event.
Please can you try the following

AddHandler export.ExcelCellFormatting, AddressOf Export_ExcelCellFormatting
Private Sub Export_ExcelCellFormatting(ByVal sender As Object, ByVal e As ExcelCellFormattingEventArgs)
    If e.GridColumnIndex = Me.RadGridView1.Columns("ColumnName").Index And e.GridRowIndex > -1 Then
        Dim sb As New System.Text.StringBuilder(Me.RadGridView1.Rows(e.GridRowIndex).Cells(e.GridColumnIndex).Value.ToString())
        e.ExcelCellElement.Render(sb)
    End If
End Sub

let me know if that helps. If not, i'll try and put a full sample together
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 06:20 PM
Hi Ryno,

I'm trying some various tests on this and it seems like this may not be the solution. I'll come back to you as soon as I can.
Richard
0
Johan
Top achievements
Rank 1
answered on 07 Feb 2011, 06:22 PM
Ah, thanks Richard. I was just busy trying out your first suggestion :-)
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 06:24 PM
Hi,

Ok, only a slight update. I believe that this will work for you

Private Sub Export_ExcelCellFormatting(ByVal sender As Object, ByVal e As ExcelCellFormattingEventArgs)
    If e.GridColumnIndex = Me.RadGridView1.Columns("ColumnName").Index And e.GridRowIndex > -1 Then
        e.ExcelCellElement.Data.DataItem = Me.RadGridView1.Rows(e.GridRowIndex).Cells(e.GridColumnIndex).Value.ToString()
    End If
End Sub

Hope that helps
Richard

EDIT// Note you might need to handle looking for NULL values too.
R
0
Johan
Top achievements
Rank 1
answered on 07 Feb 2011, 06:44 PM
Awesome, that is exactly what I was looking for.

Thanks Richard! 
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 07:26 PM
Excellent! Glad that worked for you.
Tags
GridView
Asked by
Johan
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Johan
Top achievements
Rank 1
Share this question
or