zoukankan      html  css  js  c++  java
  • js2word/html2word的简单实现

    js2word/html2word的简单实现

    以C#描述如下:
                StringBuilder sb = new StringBuilder();
                sb.Append("<html ");
                sb.Append("xmlns:o='urn:schemas-microsoft-com:office:office' ");
                sb.Append("xmlns:w='urn:schemas-microsoft-com:office:word'");
                sb.Append("xmlns='http://www.w3.org/TR/REC-html40'>");
                sb.Append("<head><title>Time</title>");


                sb.Append("<!--[if gte mso 9]>");
                sb.Append("<xml>"); 
                sb.Append("<w:WordDocument>");
                sb.Append("<w:View>Print</w:View>");
                sb.Append("<w:Zoom>90</w:Zoom>"); 
                sb.Append("<w:DoNotOptimizeForBrowser/>");
                sb.Append("</w:WordDocument>");
                sb.Append("</xml>"); 
                sb.Append("<![endif]-->");


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


                sb.Append("<body lang=EN-US style='tab-interval:.5in'>");
                sb.Append("<div class="Section1">");
                sb.Append("<h1>Time and tide wait for none</h1>"); 
                sb.Append("<p style='color:red'><I>");
                sb.Append(DateTime.Now + "</I></p>");
                sb.Append( "<img src='http://dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/logo250x135.gif'>" );
                sb.Append("</div></body></html>"); 


                Response.AppendHeader("Content-Type", "application/msword");
                Response.AppendHeader( "Content-disposition", "attachment; filename=myword.doc" );
                Response.Write(sb.ToString());
     
    Javascript版本请参考如下例子,自行修改:
  • 相关阅读:
    ant
    Java中的值传递和引用传递
    待解决的问题
    Ant生成文件解析
    JUnit初学
    遍历枚举
    2013年5月阅读链接
    《C Primer Plus》阅读笔记(3)
    《C Primer Plus》阅读笔记(2)
    《C Primer Plus》阅读笔记(4)
  • 原文地址:https://www.cnblogs.com/timssd/p/5800405.html
Copyright © 2011-2022 走看看