码迷,mamicode.com
首页 > 其他好文 > 详细

Excel 导出

时间:2015-02-11 18:00:39      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

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

Excel 导出

标签:

原文地址:http://www.cnblogs.com/zhangjinpeng/p/4286394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!