Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/1/30 1:25:18
ASP.NET页面数据导出到Excel或Word_[Asp.Net教程]

ASP.NET页面数据导出到Excel或Word_[Asp.Net教程]
private void btnMIME_Click(object sender, System.EventArgs e)
{
BindData();
Response.ContentType = "application/vnd.ms-Excel";
Response.AddHeader("Content-Disposition", "inline;filename="
+ HttpUtility.UrlEncode("下载文件.xls",Encoding.UTF8 ) );

//如果输出为word,修改为以下代码
//Response.ContentType = "application/ms-word"
//Response.AddHeader("Content-Disposition", "inline;filename=test.doc")
StringBuilder sb=new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HTMLTextWriter hw = new System.Web.UI.HTMLTextWriter(sw);
sb.Append("");
dgShow.RenderControl(hw);
sb.Append("");
Response.Write(sb.ToString());
Response.End();
}
1.若DataGrid中有按钮列,则在导出前应先将其隐藏.
2.若DataGrid有分页,而又要打印所有数据的话就应先取消分页.


If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759