数据可以完整导出来,但是没有列的标头。急需解决!
/// <summary>
/// 数据导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
string fileName = "Case History Record";
System.IO.StringWriter sw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
rpt_Mod.RenderControl(hw); Response.Clear(); Response.ContentType = "application/vnd.ms-excel";//这里设置是选择导出excel,还是word
Response.Charset = "";
rpt_Mod.Page.EnableViewState = true;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");//这里是文件名称设置
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\"><table><tr><td>");
Response.Write(sw.ToString());
Response.Write("</td></tr></table>");
Response.End();
}
已经搞定了,多谢楼上提醒!
最好贴代码
检查下,Repeater的HeaderTemplate。应该将表头放在这个节点下面,才是输入Repeater的一部分,才有可能同时导出...