时间:2021-07-01 10:21:17 帮助过:23人阅读
一、Repeater数据原样导出
DataTable dt = ViewState["DtDatat"] as DataTable; //Repeater绑定的数据源 this.Repeater1.DataSource = dt; this.Repeater1.DataBind(); DisplayDetailCol(false); //使用流方式导出Excel HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Charset = "gb2312"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Context.Server.UrlPathEncode("excel名称.xls")); //解决中文乱码问题 StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); Repeater1.RenderControl(htw); HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End();
二、动态显示/隐藏Repeater中的列
foreach (RepeaterItem item in this.Repeater1.Controls) { if (item.ItemType == ListItemType.Header) { item.FindControl("panelDetail").Visible = b; } if (item.ItemType == ListItemType.Item) { item.FindControl("lbtnDetail").Visible = b; } }
三、下载的excel显示成html格式
需要将<table>标签添加到HeaderTemplate和FooterTemplate中
四、导出的Excel数据为空或则数据都缩到一列
不要设置列的宽度为百分比
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!