关闭

net outexcel

标签: buttonexcelobject测试
277人阅读 评论(0) 收藏 举报

   Public Overloads Overrides Sub verifyrenderinginserverform(ByVal control As Control)
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Clear()
        Response.Buffer = True
        Response.Charset = "GB2312"
        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls")
        'VerifyRenderingInServerForm经测试如果设置为 GetEncoding("GB2312"),导出的文件将会出现乱码。
        Response.ContentEncoding = System.Text.Encoding.UTF7

        '设置输出文件类型为excel文件。
        Response.ContentType = "application/ms-excel"
        Dim ostringwriter As StringWriter = New StringWriter
        Dim ohtmltextwriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(ostringwriter)
        GridView3.RenderControl(ohtmltextwriter)
        Response.Output.Write(ostringwriter.ToString())
        Response.Flush()
        Response.End()
    End Sub 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10683次
    • 积分:221
    • 等级:
    • 排名:千里之外
    • 原创:13篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条