HTML编辑器内容保存在.DOCX中 [英] HTML EDITOR CONTENT Save in .DOCX

查看:158
本文介绍了HTML编辑器内容保存在.DOCX中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法将HTML内容保存到.DOCX



Cant able to save the HTML CONTENT to .DOCX

System.Text.StringBuilder strBody = new System.Text.StringBuilder("");

          strBody.Append("<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head><title>Time</title>");

          //The setting specifies document's view after it is downloaded as Print
          //instead of the default Web Layout
          strBody.Append("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>90</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->");

          strBody.Append("<style>" + "<!-- /* Style Definitions */" + "@page Section1" + "   {size:8.5in 11.0in; " + "   margin:1.0in 1.25in 1.0in 1.25in ; " + "   mso-header-margin:.5in; " + "   mso-footer-margin:.5in; mso-paper-source:0;}" + " div.Section1" + "   {page:Section1;}" + "-->" + "</style></head>");

          strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" + "<div class=Section1>" + Html_editor.Content + "</div></body></html>");

          //Force this content to be downloaded
          //as a Word document with the name of your choice


          string FullFilePath = @"C:\Users\ravikant\Desktop\AR GitHub\07-05-2014\FinalTestARGithub\LetterTemplate\"+ txtcode+ ".docx";

          FileInfo file = new FileInfo(FullFilePath);
          if (file.Exists)
          {
              ClientScript.RegisterStartupScript(this.GetType(), "disExp", "<script>alert('File Already Exists');</script>");
          }
          else
          {
              Response.AppendHeader("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
              Response.AppendHeader("Content-disposition", "inline; filename="+txtcode+".docx");
              Response.Write(strBody);
          }








推荐答案

看看这个网站。看起来它解决了你想要实现的目标。



http:// html2openxml。 codeplex.com/ [ ^ ]
Have a look at this site. It looks like it addresses what you want to achieve.

http://html2openxml.codeplex.com/[^]

这篇关于HTML编辑器内容保存在.DOCX中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆