|
Hi,
I have to export dyanmic date from grid/dataset to excel sheet with filelds in C# with .Net. Datbase is sqlserver 2000
I donot know how to do?
please guide me.
Regards,
eshwar_gp
|
|
|
Here is some vb.net code that works
<%@ Import Namespace="System.IO" %>
Sub Click_Excel(S as Object,E as EventArgs)
Response.Cache.SetExpires(DateTime.Now.AddSeconds(1))
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
EnableViewState = false
Dim tw as new StringWriter()
Dim hw as new HtmlTextWriter(tw)
GridOpen.RenderControl(hw)
dim fName as String
Fname = "TTCR" & format(Now,"HH_MM") & "/forum/.xls"
'Fname is the default filename given to the user in the save as box
Response.AppendHeader("content-disposition","attachment;filename=" & Fname )
Response.Write(tw.ToString())
Response.End()
End Sub
Good Luck
|
|
|
use the following line to print the data in excel
Response.ContentType="application/vnd.ms-excel";
place the above line where ever u want and execute
|
|
|
|
|
|
|
// |