1
我有以下代碼導出一個gridview到excel和導出工作得很好。問題在於,無論我做什麼,它都將文件命名爲webform .xls的名稱,而不是我在代碼(Team.xls)中提供的名稱。導出gridview到excel在VB.Net不採取提供的文件名?
Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExcell.Click
Dim sw As New StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(sw)
Dim frm As HtmlForm = New HtmlForm()
Page.Response.AddHeader("content-disposition", "attachment;Team.xls")
Page.Response.ContentType = "application/vnd.ms-excel"
Page.Response.Charset = ""
Page.EnableViewState = False
frm.Attributes("runat") = "server"
Controls.Add(frm)
frm.Controls.Add(gvTeam)
frm.RenderControl(hw)
Response.Write(sw.ToString())
Response.End()
End Sub
這就是答案 - 謝謝。 – 2011-06-10 15:30:42
歡迎您:) – 2011-06-10 15:31:05