[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

datagrid column to excel column

Posted on 2004-10-29
2
Medium Priority
?
208 Views
Last Modified: 2011-09-20
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?
0
Comment
Question by:gotzcomputer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:gotzcomputer
ID: 12465509
I guess what I really want is how to copy my dataset over to an excel worksheet
0
 
LVL 4

Accepted Solution

by:
computerg33k earned 500 total points
ID: 12506774
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question