web 横向导出word

来源:互联网 发布:招标软件 编辑:程序博客网 时间:2024/05/16 05:02
  1. <html>  
  2. <head>  
  3.     <title>web横向导出word</title>  
  4.     <script type="text/javascript">  
  5.         function AutomateWord(tableid,reportName)  
  6.         {    
  7.             try{   
  8.                 var oWD = new ActiveXObject("Word.Application");      
  9.             }catch(e){   
  10.                 alert("无法调用Office对象,请确保您的机器已安装了Office并已将本系统的站点名加入到IE的信任站点列表中!");   
  11.                 return;   
  12.             }    
  13.             //默认为页面视图  
  14.             var oDC = oWD.Documents.Add("",0,0);   
  15.               
  16.             oWD.ActiveDocument.PageSetup.TopMargin = 2.5/0.035;  
  17.             oWD.ActiveDocument.PageSetup.LeftMargin = 2.5/0.035;  
  18.             oWD.ActiveDocument.PageSetup.BottomMargin = 2.5/0.035;  
  19.             oWD.ActiveDocument.PageSetup.RightMargin = 2.5/0.035;  
  20.             //oWD.ActiveDocument.PageSetup.LinesPage = 0;  
  21.               
  22.             var oRange =oDC.Range(0,1);     
  23.             var sel = document.body.createTextRange();     
  24.             sel.moveToElementText(tableid);     
  25.             sel.select();     
  26.             sel.execCommand("Copy");     
  27.             oRange.Paste();      
  28.             //oWD.ActiveDocument.ActiveWindow.View.Type=3 //设定显示为页面视图状态  
  29.             oWD.ActiveWindow.Caption=reportName;     
  30.             oWD.Application.DefaultSaveFormat = "doc"   
  31.             oWD.Application.Visible = true;   
  32.         }  
  33.     </script>  
  34.       
  35.     <style type="text/css">  
  36.         span.pagebreak{line-height: 125%;}  
  37.         span br.brbreak{page-break-before: always; mso-break-type: section-break;}  
  38.         div.Section1{page: Section1;}  
  39.         div.Section2{page: Section2;}  
  40.         @page Section2{size: 29.7cm 21.0cm;mso-page-orientation: landscape; }  
  41.     </style>  
  42. </head>  
  43. <body>  
  44.     <div>  
  45.         <input id="btnDc" type="button" value="导出" onclick="AutomateWord(dc,'web横向导出word')" />   
  46.     </div>  
  47.       
  48.     <div id="dc" style="width:21cm; padding:2.52cm auto; margin-right:auto; margin-left:auto;">  
  49.         <div class="Section1">  
  50.             排版:竖   
  51.         </div>  
  52.         <span class="pagebreak">  
  53.             <br clear="all" class="brbreak" />   
  54.         </span>  
  55.    
  56.         <div class="Section2">  
  57.             排版:横  
  58.         </div>   
  59.           
  60.         <!--------------此处换页符不可省略,否则无法横向导出-------------->  
  61.         <span class="pagebreak">  
  62.             <br clear="all" class="brbreak" />   
  63.         </span>  
  64.     </div>       
  65. </body>  
  66. </html>  
0 0