Js使用word書簽填充內容


Js使用word書簽填充內容

1.在模板文件中需要填充的地方插入書簽

填充內容為:(|光標所在處)

填寫書簽名,點擊添加完成:

2.使用js打開模板,獲取書簽位置,填充數據:

function printWord(flag){

    var word;

    try{

        word = new ActiveXObject("Word.Application");

        word.visible = false;

       }catch(e){

           alert("確認是否安裝了OFFICE軟件,是否添加了受信站點,是否將ActiveX控件啟用!");

           return ;

       }

       try {//打開模板文件

            word.Visible = false;

         var oDocument = word.Documents.open("http://"+document.location.host+"/web/word/DC001.doc");

     }catch(Exception) {

          word.quit();

          word = null;

             return ;

  }

  //獲取書簽位置,填充內容

  try{

       var range = word.Range;

       range = word.ActiveDocument.Bookmarks(“bookmarkname”).Range;

    range.InsertBefore(“需要插入的內容”); //書簽后插入內容

    //word.Application.Printout();//打印

    word.quit();

    word=null;

  }catch(e){

    alert("書簽賦值出現錯誤"+e.toString());

    word.quit();

    word=null;

  }

}

printWord() ;

3.完成導出、打印

//word.Application.Printout();//打印


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM