datagrid column to excel column

i have my data going into a datagrid.  now i need to get the data from the datagrid to an excel worksheet.  how do i get the data column to an excel column?
gotzcomputerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gotzcomputerAuthor Commented:
I guess what I really want is how to copy my dataset over to an excel worksheet
0
computerg33kCommented:
try this:
       Dim oResizeRange As Excel.Range
        Dim oXL As Excel.Application
        Dim oWB As Excel.Workbook
        Dim oSheet As Excel.Worksheet
        Dim oRng As Excel.Range

        'Instantiate Jobs Object
        Dim objGrabowski As New ExcelGrabowskiAttempt()
        objGrabowski.JobID = iJobID
        objGrabowski.ClientPK = iClientPK

        Try
            Dim ds As DataSet = objGrabowski.GetGrabowski
            Dim frmGrabowskiReports As New frmGrabowskiReports()

            frmGrabowskiReports.propDataSet = ds
            frmGrabowskiReports.ShowDialog()

            If frmGrabowskiReports.propGenerate Then

                Dim dt As DataTable
                dt = frmGrabowskiReports.propDataSet.Tables("Grabowski")

                'For iIndex = 0 To dt.Rows.Count - 1

                '*******************Start of Excel Sheet
                ' Start Excel and get Application object.
                oXL = CType(CreateObject("Excel.Application"), Excel.Application)
                oXL.Visible = True

                ' Get a new workbook.
                oWB = oXL.Workbooks.Add
                oSheet = CType(oWB.ActiveSheet, Excel.Worksheet)

                With oSheet.Range("A1", "W1")
                    .Font.Bold = True
                    .VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
                End With
                '*******************************************************************************************
                Dim mrow As DataRow
                Dim colindex As Integer
                Dim rowindex As Integer
                Dim col As DataColumn

                For Each col In dt.Columns
                    colindex += 1
                    oXL.Cells(1, colindex) = col.ColumnName
                Next
                rowindex = 1

                For Each mrow In dt.Rows
                    rowindex += 1
                    colindex = 0
                    For Each col In dt.Columns
                        colindex += 1
                        oXL.Cells(rowindex, colindex) = mrow(col.ColumnName).ToString()
                        objGrabowski.GetGrabowskiDetail()
                    Next
                Next
            End If
            ' AutoFit columns A.
            oRng = oSheet.Range("A23", "W23")
            oRng.EntireColumn.AutoFit()

            ' Make sure Excel is visible and give the user control
            ' of Excel's lifetime.
            oXL.Visible = True
            oXL.UserControl = True

            ' Make sure that you release object references.
            oRng = Nothing
            oSheet = Nothing
            oWB = Nothing
            oXL = Nothing

            Exit Sub
        Catch
        End Try
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.