我的数据是自己手工生产,然后repeater绑定,最后导出excel,但出现问题,谁可以给个例子什么的没有。
关键代码如下:
protected void LinkButton1_Click(object sender, EventArgs e)
{
string time = DateTime.Now.ToString("yyyyMMddhhmmss");
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + time + ".xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";
Panel1.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
Panel1.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
这个能导出,但是没有按列显示,而且还有Html的元素