Hi Ramesh,
use this below code.
Private Sub btn_export1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_export1.Click
Try
Dim excel As New Excel.ApplicationClass
Dim wBook As Excel.Workbook
Dim wSheet As Excel.Worksheet
wBook = excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
Dim dt As System.Data.DataTable = ds2.Tables(0)
Dim dc As System.Data.DataColumn
Dim dr As System.Data.DataRow
Dim colIndex As Integer = 0
Dim rowIndex As Integer = 0
rowIndex = rowIndex + 1
'excel.Cells(1, rowIndex) = "Mother Theresa College Of Engi
Tech"
excel.Cells(1, 4) = main_From.txt_name.Text + " : Attendence
Reports "
excel.Cells(1, 5) = "Date Form:" + txt_from1.Text
excel.Cells(1, 6) = " To:" + txt_to1.Text
For Each dc In dt.Columns
colIndex = colIndex + 1
excel.Cells(2, colIndex) = dc.ColumnName.ToUpper
Next
For Each dr In dt.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each dc In dt.Columns
colIndex = colIndex + 1
excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
Next
Next
wSheet.Columns.AutoFit()
'Dim strFileName As String = "D:\ani.xls"
'Dim blnFileOpen As Boolean = False
Try
'Dim fileTemp As System.IO.FileStream =
System.IO.File.OpenWrite(strFileName)
'fileTemp.Close()
Catch ex As Exception
'blnFileOpen = False
End Try
' If System.IO.File.Exists(strFileName) Then
'System.IO.File.Delete(strFileName)
'End If
'wBook.SaveAs(strFileName)
'excel.Workbooks.Open(strFileName)
excel.Visible = True
Catch ex As Exception
End Try
End Sub
On Mon, Oct 24, 2011 at 5:40 AM, Ramesh Arumugam <[email protected]> wrote:
> Hi all,
>
> How to export a gridview to excel in .net windows application?
>
> Thanks,
>
> Ramesh Arumugam
> +91 900 344 344 2
> Linked in:http://in.linkedin.com/in/ramesharumugam43
>
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> 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
>
--
Thanks&Regard's
Mahendar.M,
New york,
571-296-6271.
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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