Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)delvpublished in(发表于) 2014/1/8 7:04:09 将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("
来源:网络
赞