我创建了一个ASP.net网站,后端代码在Vb中我生成了一个按钮,用于将内容保存在excel文件中,但当Excel尝试打开文件时,我收到以下消息。
*'FileName.xls'的格式和扩展名不匹配。该文件可能已损坏或不安全。除非您信任其来源,否则请勿打开它。你想打开吗?
我正在附加我的aspx.vb代码
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
GridView5.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.[End]()
End Sub