以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版本请参考如下例子,自行修改:
js2excel/html2excel的简单实现原文链接:https://www.cnblogs.com/timssd/p/5800405.html
本文来源 爱码网,其版权均为 原网址 所有 与本站无关,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源。