Hi, U can get this code from this link which is in vb.net - http://nishantpant.wordpress.com/2006/11/02/exporting-data-to-excel-from -a-windows-forms-net-application/ Private Sub ExportGridToExcel() Dim Excel As Object = CreateObject("Excel.Application") If Excel Is Nothing Then MsgBox("It appears that Excel is not installed on this machine. This operation requires MS Excel to be installed on this machine.", MsgBoxStyle.Critical) Return End If 'Make Excel visible Excel.Visible = True 'Initialize Excel Sheet With Excel .SheetsInNewWorkbook = 1 .Workbooks.Add() .Worksheets(1).Select() 'Add header row to Excel Sheet by copying column headers from the Datagrid Dim Col As DataGridViewColumn Dim i As Integer = 1 For Each Col In dgRemovaLog.Columns .Cells(1, i).Value = Col.HeaderText i += 1 Next 'Add data to excel sheet by looping through the rows 'in the datagrid i = 2 Dim RowItem As DataGridViewRow Dim Cell As DataGridViewCell For Each RowItem In dgRemovaLog.Rows Dim j As Integer = 1 For Each Cell In RowItem.Cells .Cells(i, j).Value = Cell.Value j += 1 Next i += 1 Next End With System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel) Excel = Nothing MsgBox("Export to Excel Complete", MsgBoxStyle.Information) End Sub
_____ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Raza Sent: Sunday, June 03, 2007 01:38 PM To: [email protected] Subject: [.NetIndia] Re: How to Export Datatable to Excel Sheet Hi, How to Export Datatable to Excel sheet using C#. Regards Raza On 5/29/07, Ramkumar A K <[EMAIL PROTECTED]> wrote: Hi, How to Export Datatable to Excel sheet using Vb.net.. Regards, Ramkumar.A.K. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups ".NetIndia" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/TechdotNetIndia?hl=en -~----------~----~----~----~------~----~------~--~---
