sunshinewen1987
2017-11-21 10:13asp.net 导出word文档问题
pload/201711/21/1511259339_992470.png)
前台:
后台: HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("报名表.doc", System.Text.Encoding.UTF8));
HttpContext.Current.Response.ContentType = "application/ms-word";
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
//关闭控件的视图状态
Page.EnableViewState = false;
//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
Page.RenderControl(htmlWriter);
//输出
string pageHtml = writer.ToString();
int startIndex = pageHtml.IndexOf("<html");
int endIndex = pageHtml.LastIndexOf("</div>");
int lenth = endIndex - startIndex;
pageHtml = pageHtml.Substring(startIndex, lenth);
// pageHtml = pageHtml.Remove(pageHtml.LastIndexOf("<div class=\"flowbar\">"));
HttpContext.Current.Response.Write(pageHtml.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
问题:1 为什么会出现自动换行; 2 怎么会出现窗体?
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- asp.net中导出DataGrid内容为word遇到的问题!
- html5
- word
- textbox控件
- 1个回答
- 从SQL数据库中获取数据写入WORD文档,请附加代码,谢谢
- sql
- asp.net
- 3个回答