Export Data from VB 2008 to Excel

Dim ExcelApp As Object, ExcelBook As Object
Dim
ExcelSheet As
Object
Dim
i As
Integer
Dim
j As Integer

‘create object of excel

ExcelApp = CreateObject(“Excel.Application”)
ExcelBook = ExcelApp.WorkBooks.Add
ExcelSheet = ExcelBook.WorkSheets(1)

With ExcelSheet
    For i = 1 To Me.DataGridView1.RowCount
         .cells(i, 1) =
Me.DataGridView1.Rows(i – 1).Cells(“id”).Value
        
For j = 1 To DataGridView1.Columns.Count – 1
              .cells(i, j + 1) = DataGridView1.Rows(i – 1).Cells(j).Value
        
Next
    Next
End
With

Download Source Code and See More

One Response to “Export Data from VB 2008 to Excel”

  1. chhin veth Says:

    សូមអរគុណនូវឯកសារដែលបានផ្ញើតាមតម្រូវការ


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: