Thursday, 3 January 2013

Export Data from Excel files with special characters


Dim grd1 As New GridView()
grd1.DataSource = dt ' dt is Data Table
grd1.DataBind()

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=products.xls")
Response.Charset = ""

Response.ContentEncoding = Encoding.Unicode
Response.BinaryWrite(Encoding.Unicode.GetPreamble())

Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
grd1.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()

No comments:

Post a Comment