Ramesh, Here is a function I wrote a few years ago that copies the contents of a DataTable to Excel.
Public Shared Function GenerateTabularReport_ReturnWorksheet(ByVal Data As DataTable) As Excel.Worksheet Dim xlApp As New Excel.Application Dim xlWorkbook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim intRowIndex As Integer Dim intColIndex As Integer xlWorkbook = xlApp.Workbooks.Add() xlSheet = xlWorkbook.ActiveSheet ' Create Column Headers For intColIndex = 1 To Data.Columns.Count xlSheet.Cells(1, intColIndex).Value = Data.Columns(intColIndex - 1).Caption Next xlSheet.Rows(1).Font.Bold = True xlSheet.Range("A2").Select() xlApp.ActiveWindow.FreezePanes = True ' Generate Data Rows For intRowIndex = 2 To Data.Rows.Count + 1 For intColIndex = 1 To Data.Columns.Count xlSheet.Cells(intRowIndex, intColIndex).value = Data.Rows(intRowIndex - 2).Item(intColIndex - 1) Next Next ' AutoSize columns to fit data xlSheet.Columns("A:" + GetLetter(Data.Columns.Count)).AutoFit() xlApp.Visible = True Return xlSheet End Function Hope it helps, Justin Steen -- You received this message because you are subscribed to the Google Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting" group. To post to this group, send email to dotnetdevelopment@googlegroups.com To unsubscribe from this group, send email to dotnetdevelopment+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en or visit the group website at http://megasolutions.net