Feedback

VB - ASP.Net Gridview to Excel

Veröffentlicht von am 06.04.2009
(2 Bewertungen)
Gibt ein beliebiges Gridview als Excelfile aus.
 Sub GridView2CSV(ByVal myGridview As GridView, ByVal File As String)

        ''// Get the Columns of the Gridview

        Dim ColumnsCount As Integer = myGridview.Columns.Count - 1

        ''// Get and Write the HeaderNames

        Dim HeaderNames As String = Nothing

        For i = 0 To ColumnsCount

            HeaderNames += myGridview.Columns(i).HeaderText & ";"

        Next

        CW(HeaderNames, File)

        ''// Get the Rows Content

        Dim RowValue As String = Nothing


        For Each myRow As GridViewRow In myGridview.Rows

            For i = 0 To ColumnsCount

                RowValue += myRow.Cells(i).Text & ";"

            Next

            CW(RowValue, File)

            RowValue = Nothing

        Next

    End Sub

    Sub CW(ByVal Text, ByVal FileName)

        Dim myFileWriter As New System.IO.StreamWriter(FileName, True)

        myFileWriter.WriteLine(Text)

        myFileWriter.Close()

    End Sub


End Class

Abgelegt unter GridView, Excel, CSV, ASP.Net, VB.Net.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!