小技巧之js导出word

js导出word方法,简单,但是功能上要弱一些

 

function copyTable(){
  //tabel、div ID, 会将table内所有的内//容复制到word

  var elTable = document.getElementById("aa");
  var oRangeRef = document.body.createTextRange();
  oRangeRef.moveToElementText( elTable );
  oRangeRef.execCommand( "Copy" );

     var appWord = new ActiveXObject( "Word.Application" );
      appWord.Application.Visible = true;
       var mydoc=appWord.Documents.Add('',0,1);
       myRange =mydoc.Range(0,1);
      
       myRange.Paste();
       appWord.ActiveWindow.ActivePane.View.Type=7;//4,打印预览;3,word导出;7,分页
       appWord = null;

 }

你可能感兴趣的:(JavaScript,word)