动态生成WORD内容

 
  1. //动态生成WORD内容   
  2.    StringBuilder strBody = new StringBuilder();   
  3.    strBody.Append("<html " +   
  4.        "xmlns:o='urn:schemas-microsoft-com:office:office' " +   
  5.        "xmlns:w='urn:schemas-microsoft-com:office:word'" +   
  6.        "xmlns='http://www.w3.org/TR/REC-html40'>" +   
  7.        "<head><title>Time</title>");   
  8.   
  9.    //   
  10.    strBody.Append("<!--[if gte mso 9]>" +   
  11.                         "<xml>" +   
  12.                         "<w:WordDocument>" +   
  13.                         "<w:View>Print</w:View>" +   
  14.                         "<w:Zoom>90</w:Zoom>" +   
  15.                         "<w:DoNotOptimizeForBrowser/>" +   
  16.                         "</w:WordDocument>" +   
  17.                         "</xml>" +   
  18.                         "<![endif]-->");   
  19.   
  20.    strBody.Append("<style>" +   
  21.                        "<!-- /* Style Definitions */" +   
  22.                        "@page Section1" +   
  23.                        "   {size:8.5in 11.0in; " +   
  24.                        "   margin:1.0in 1.25in 1.0in 1.25in ; " +   
  25.                        "   mso-header-margin:.5in; " +   
  26.                        "   mso-footer-margin:.5in; mso-paper-source:0;}" +   
  27.                        " div.Section1" +   
  28.                        "   {page:Section1;}" +   
  29.                        "-->" +   
  30.                       "</style></head>");   
  31.   
  32.    strBody.Append("<body lang=EN-US style='tab-interval:.5in'>" +   
  33.                        "<div class=Section1>" +   
  34.                        "<h1>Time and tide wait for none</h1>" +   
  35.                        "<h1>时不待人</h1>"+   
  36.                        "<p style='color:red'><I>" +   
  37.                        DateTime.Now + "</I></p>" +   
  38.                        "</div></body></html>");   
  39.   
  40.    //Force this content to be downloaded   
  41.    //as a Word document with the name of your choice   
  42.    Response.AppendHeader("Content-Type", "application/msword");   
  43.    Response.AppendHeader("Content-disposition", "attachment; filename=myword.doc");   
  44.   
  45.    Response.Write(strBody);  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值