VB.NET DATAGRID或DATASET 输出CSV文件

Dim lstSelect As New LstConstrol
        Dim DstTemp As DataSet
        Dim strTemp As String
        Dim strData As String
        'DATASET循环用变量
        Dim TempRow As DataRow
        Dim TempColumn As DataColumn
        'DATAGRID循环用变量
        Dim TempItem As DataGridItem
        Dim TempGridCol As DataGridColumn
        Dim i As Int32

        DstTemp = lstSelect.SelectAll()
        drgShow.DataSource = DstTemp
        drgShow.DataBind()
        'dataset循环读取
        'For Each TempRow In DstTemp.Tables(0).Rows
        '    For Each TempColumn In DstTemp.Tables(0).Columns
        '        strData += TempRow(TempColumn).ToString() + ","
        '    Next
        '    strData += ControlChars.CrLf
        'Next

        'datagrid循环读取
        '表头循环读取
        For Each TempGridCol In drgShow.Columns
            strData += TempGridCol.HeaderText + ","
        Next
        strData += ControlChars.CrLf
        '内容循环读取
        For Each TempItem In drgShow.Items
            For i = 0 To drgShow.Columns.Count - 1
                strData += TempItem.Cells(i).Text + ","
            Next
            strData += ControlChars.CrLf
        Next

        '生成输出流.输出csv
        strTemp = String.Format("attachment;filename={0}", "ExportData.csv")
        Response.ContentEncoding = Encoding.GetEncoding("Gb2312")
        Response.ClearHeaders()
        Response.AppendHeader("Content-disposition", strTemp)
        Response.Write(strData)
        Response.End()

阅读更多
想对作者说点什么? 我来说一句

datatable、datagridview导出为csv

2012年10月26日 8KB 下载

没有更多推荐了,返回首页

不良信息举报

VB.NET DATAGRID或DATASET 输出CSV文件

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭