asp.net中如何把动态生成的table中的数据导入EXCEL
table是动态生成的,体现了ajax静态分页的功能,其中table是客户端控件,我在table中添加了runat="server",我这样写为什么只导出aspx页面Re...
table是动态生成的,体现了ajax静态分页的功能,其中table是客户端控件,我在table中添加了runat="server",我这样写为什么只导出aspx页面
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=table.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.tab.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End(); 展开
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=table.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.tab.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End(); 展开
展开全部
HttpContext.Current.Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("名单模版.xls", System.Text.Encoding.UTF8));
HttpContext.Current.Response.BinaryWrite(by);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
//通知浏览器下载文件而不是打开
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("名单模版.xls", System.Text.Encoding.UTF8));
HttpContext.Current.Response.BinaryWrite(by);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
追问
HttpContext.Current.Response.BinaryWrite(by);其中by是字节数组,现在的问题就是如何得到table中的数据,我不想一行一列的读取,就想把table中的数据快捷的导入到Excel中
追答
你用的是GridView 是不,,他有个属性 是table ,,取出来就是 Table,,
然后直接 转流 下载就行咯啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询