导出gridview以优于VB.Net而不提供提供的文件名?

时间:2011-06-10 15:12:56

标签: asp.net vb.net excel gridview export-to-excel

我有以下代码将gridview导出到excel,导出工作正常。问题是,无论我做什么,它都会将文件命名为webform .xls,而不是我在代码中提供的名称(Team.xls)。

 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

1 个答案:

答案 0 :(得分:4)

您忘记提及filename=Team.xls

应该是"attachment;filename=Team.xls"而不是attachment;Team.xls