zoukankan      html  css  js  c++  java
  • Excel 导出

    admin = Context.Request.Cookies["user"].Values["username"].ToString();
                    Hashtable hash = new Hashtable();
                    hash.Add("p2", admin);
                    hash.Add("p_state", 2);
                    //DataSet ds = Bll.ProjectInfoBll.SelectAll_state(hash) as DataSet;
                    //DataTable dt = ds.Tables[0];
                    //ViewState["DtDatat"] = ds.Tables[0];
                    Repeater1.DataSource = Bll.ProjectInfoBll.SelectAll_state(hash);
                    this.Repeater1.DataBind();
                    string strnum = DateTime.Now.ToString("F");
                    //CreateExcel(tmbll, strnum + ".xls");
                    HttpResponse response = Page.Response;
                    Response.Clear();
                    Response.Buffer = true;
                    Response.Charset = "utf-8";
                    //解决导出到Excel2007乱码问题
                    Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
                    Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strnum, System.Text.Encoding.UTF8) + ".xls");
                    //解决导出到Excel2007乱码问题
                    //解决导出到Excel2007乱码问题
                    Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");(这个是关键)
                    //Response.ContentEncoding = System.Text.Encoding.UTF8;     //设置输出流为简体中文
                    Response.ContentType = "application/ms-excel";    //设置输出文件类型为excel文件。
                    this.EnableViewState = false;
                    System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
                    System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
                    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                    //   repeater控件的ID
                    Repeater1.RenderControl(oHtmlTextWriter);
                    Response.Write(oStringWriter.ToString());
                    Response.End();

  • 相关阅读:
    xxx
    cdq分治入门--BZOJ1176: [Balkan2007]Mokia
    cdq分治入门--BZOJ3262: 陌上花开
    本月题量 171122晚-171222午
    cdq分治入门--BZOJ1492: [NOI2007]货币兑换Cash
    NOIP2017游记
    xx
    CF601D:Acyclic Organic Compounds
    LOJ#539. 「LibreOJ NOIP Round #1」旅游路线
    composer常用的一些命令参数说明
  • 原文地址:https://www.cnblogs.com/zhangjinpeng/p/4286394.html
Copyright © 2011-2022 走看看