I've already try generate excel by using C#, It works exactly.
However, I convert this code into VB.Net. It doesn't work. The following is my VB Code:
What's wrong with my VB Code?
VB.NET:
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
However, I convert this code into VB.Net. It doesn't work. The following is my VB Code:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Clear()
Page.EnableViewState = False
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachmentfilename=""YourReportName.xls""")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite = New System.IO.StringWriter
Dim htmlWrite = New HtmlTextWriter(stringWrite)
myDataGrid.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
End Sub
What's wrong with my VB Code?