Hi, I would like to export the data from GridView to Excel 2007 file (xlsx). Here is my code. However,I get an error message: The file you are trying to open is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?Help.:confused:Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Clear() Response.Buffer = True Response.Charset = "" Response.AppendHeader("Content-Disposition", "attachment;filename=statistic.xlsx") Response.ContentEncoding = System.Text.Encoding.UTF7 Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter) Me.GridView1.RenderControl(oHtmlTextWriter) Response.Output.Write(oStringWriter.ToString) Response.Flush() Response.End()End SubPublic Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)End Sub 解决方案 这篇关于如何将GridView导出到Excel 2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 21:01