repeater嵌套repeater 导出成Excel
如图所示
导出成excel,本人会导的都是一个datatable,这下不知道如何都导出来了,有做过的高人指点一下了,谢谢!
------解决方案-------------------- /// <summary>
/// 将DataTable 导出为EXCEL,并直接提供下载
/// </summary>
/// <param name="ds">需要导处的DataTable</param>
/// <param name="fileName">到处生成的文件名</param>
///
public bool ExportExcelByDataTable(DataTable dt, string fileName)
{
try
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "utf-7";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-7");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DataGrid dg = new DataGrid();
dg.HeaderStyle.CssClass = "dgHead";
dg.DataSource = dt;
dg.DataBind();
dg.RenderControl(htmlWrite);
// GridView gv = new GridView();
// gv.HeaderStyle.CssClass = "gvHead";
// gv.DataSource = dt;
// gv.DataBind();
// gv.RenderControl(htmlWrite);
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ".xls");
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
HttpContext.Current.Response.End();
return true;
}
catch
{
return false;
}
}
------解决方案--------------------//列表输出
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
rpList.RenderControl(hw); //repeater
Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
------解决方案--------------------调用的时候 Export("application/ms-excel", "XXXXX.xls");
------解决方案--------------------打开EXCEL模板导出excel
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
rpt.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
------解决方案--------------------方法1:用office组件生产excel,
//此代码基于vs2005下的vsto2005平台下的部分代码。
private void DataBind()