sunshinewen1987 2017-11-21 10:13 采纳率: 0%
浏览 929

asp.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条回答 默认 最新

  • threenewbee 2017-11-21 16:07
    关注

    你这个导出的不是word而是html,只是因为word也支持打开html文档的缘故,好像是word文档。
    要导出真正的word文档,需要用npoi这个第三方的库。

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器