我将DataGrid的数据导入Excel中后,我想让其中某些列的不导入Excel中,怎么做呢?(即datagrid中显示,而在excel中某些列让其不显示)
谢谢

解决方案 »

  1.   

    我的方法,你可以在sql中取向要得字段内容        Dim cnn As New OleDbConnection(G_strCnn)
            Dim com As New OleDbCommand("SELECT * FROM " & strTableName & " Where 0=0" & strsqlcon, cnn)
            Dim dr As OleDbDataReader
            Dim strFilePath As String
            strFilePath = Request.MapPath("..")
            strFilePath += "\cache\" & strTableComment & ".csv"
            If IO.File.Exists(strFilePath) Then
                Try
                    IO.File.Delete(strFilePath)
                Catch ex As Exception
                End Try
            End If        Dim excelFile As New IO.StreamWriter(strFilePath, False, System.Text.Encoding.Default)
            Dim sHttpFileName As String
            Dim iRow, iCol As Integer
            iRow = 1
            Try
                cnn.Open()
                dr = com.ExecuteReader            Dim strTitle As String
                For iCol = 1 To dr.FieldCount
                    strTitle = strTitle & funGetFieldName(dr.GetName(iCol - 1), strTableName) & ","
                    'myWorkSheet.Cells(iRow, iCol) = dr.GetName(iCol - 1)
                Next
                excelFile.WriteLine(strTitle)
                iRow += 1
                Dim strText As String            Do While dr.Read
                    For iCol = 1 To dr.FieldCount
                        strText = strText & dr.Item(iCol - 1) & ","
                    Next
                    excelFile.WriteLine(strText)
                    strText = ""
                    iRow += 1
                Loop            Try
                    excelFile.Flush()
                    excelFile.Close()
                Finally
                End Try            Response.ClearHeaders()
                Response.ClearContent()
                Response.ContentType = "text/csv"
                Response.AddHeader("Content-Disposition:", "attachment; filename=" & HttpUtility.UrlEncode(strFilePath))
                Try
                    Response.WriteFile(strFilePath)
                    Response.Flush()
                    Response.Close()
                    Response.End()
                    Call subLog("结构化数据", "导出" & strTableComment & "为Excel!", strJH)
                Catch ex As Exception
                    Response.Redirect("../error/szjt_cw.htm")
                End Try        Catch ex As Exception
                Response.Redirect("../error/szjt_cw.htm")
            Finally
                dr.Close()
                'dr.Dispose()
                com.Dispose()
                cnn.Close()
                cnn.Dispose()
            End Try
      

  2.   

    http://community.csdn.net/Expert/TopicView.asp?id=3346620
      

  3.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=8A4CBF47-B888-4832-3389-ED3A3A3C8AAB