ASP.NET EXPORT TO EXCEL
-
After export gridview to excel using asp.net and vb.net Save as Type:Web Page. I want it should be Microsoft Office excel workbook My code like this ==================== gvRpt.AllowPaging = False gvRpt.GridLines = GridLines.Both Dim style As String = " .text { mso-number-format:\@; } </script> " Response.ClearContent() Response.Clear() Response.Buffer = True Response.Charset = "" Me.EnableViewState = False Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls") Response.ContentType = "application/excel" 'Response.ContentType = "application/vnd.ms-excel" Dim sw As New StringWriter() Dim htw As New HtmlTextWriter(sw) gvRpt.RenderControl(htw) Response.Write(style) Response.Write(sw.ToString()) Response.End()</x-turndown>
-
After export gridview to excel using asp.net and vb.net Save as Type:Web Page. I want it should be Microsoft Office excel workbook My code like this ==================== gvRpt.AllowPaging = False gvRpt.GridLines = GridLines.Both Dim style As String = " .text { mso-number-format:\@; } </script> " Response.ClearContent() Response.Clear() Response.Buffer = True Response.Charset = "" Me.EnableViewState = False Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls") Response.ContentType = "application/excel" 'Response.ContentType = "application/vnd.ms-excel" Dim sw As New StringWriter() Dim htw As New HtmlTextWriter(sw) gvRpt.RenderControl(htw) Response.Write(style) Response.Write(sw.ToString()) Response.End()</x-turndown>
try below code.
gvRpt.AllowPaging = False
gvRpt.GridLines = GridLines.Both
Dim style As String = " .text { mso-number-format:\@; } </script> "
Response.ClearContent()
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Me.EnableViewState = False
Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls")
Response.ContentType = "application/vnd.ms-excel"
Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
gvRpt.RenderControl(htw)
Response.Write(style)
Response.Write(htw.ToString())
Response.End()</pre>hope it works.
<div class="signature">Vande Matharam - Jai Hind</div></x-turndown> -
try below code.
gvRpt.AllowPaging = False
gvRpt.GridLines = GridLines.Both
Dim style As String = " .text { mso-number-format:\@; } </script> "
Response.ClearContent()
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Me.EnableViewState = False
Response.AddHeader("content-disposition", "attachment;filename=" & RptName & ".xls")
Response.ContentType = "application/vnd.ms-excel"
Dim sw As New StringWriter()
Dim htw As New HtmlTextWriter(sw)
gvRpt.RenderControl(htw)
Response.Write(style)
Response.Write(htw.ToString())
Response.End()</pre>hope it works.
<div class="signature">Vande Matharam - Jai Hind</div></x-turndown> -
Also you did not see it on the first view? Just one variable in one line was changed: Your line is:
Response.Write(sw.ToString())
His line is:Response.Write(htw.ToString())
I.e.sw
was replaced byhtw
. -
Also you did not see it on the first view? Just one variable in one line was changed: Your line is:
Response.Write(sw.ToString())
His line is:Response.Write(htw.ToString())
I.e.sw
was replaced byhtw
.