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/[^]

>