关闭

保存为Excel文件

271人阅读 评论(0) 收藏 举报

    Response.Clear();
    Response.Buffer= true;
    Response.Charset="GB2312";
    string fileName = Server.UrlEncode(nameTxt.Value);
    if(fileName == "")
     fileName = "file";

    Response.AppendHeader("Content-Disposition","attachment;filename=" + fileName + ".xls");
    Response.ContentType = "application/ms-excel";
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");

    this.EnableViewState = false;

    System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("zh-CHS",true);
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
    this.RenderControl(oHtmlTextWriter);
    Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
    Response.Write(oStringWriter.ToString());
    Response.End();

0
0

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