保存为Excel文件

    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();

阅读更多
文章标签: excel string file
个人分类: 源码
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

保存为Excel文件

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭