日期:2014-05-17  浏览次数:20669 次

js导出html页面到word中的问题求解

function AllAreaWord()
{

 var oWD = new ActiveXObject("Word.Application");
 var oDC = oWD.Documents.Add("",0,1);
 var oRange =oDC.Range(0,1);
 var sel = document.body.createTextRange();
 sel.moveToElementText(PrintA);
 sel.select();
 sel.execCommand('Copy');
 oRange.Paste(); 
 oWD.Application.Visible = true;
 window.close();
}


代码执行后,进程中有word进程,但是却没打开word,有知道怎么解决的吗
javascript

------解决方案--------------------
之前做过这个功能,把代码给你看下:
function htmlToWord()
{
var WordApp;
        var Doc;
        try{
         WordApp = new ActiveXObject("Word.Application");
         WordApp.Application.Visible=true; 
                XQKBpage.focus();
                XQKBpage.document.execCommand("SelectAll");
                XQKBpage.document.execCommand("Copy");
                Doc=WordApp.Documents.Add();
                Doc.Content.Paste();
                Doc.SaveAs("D:\\内容"+new Date().getFullYear()+ (new Date().getMonth()+1)+ new Date().getDate()+new Date().getHours()+new Date().getMinutes()+".doc"); 
                try{
                        Doc.Close();
                }catch(e){};

                WordApp.DisplayAlerts=true ;
                WordApp.Quit();
                alert("已将内容成功保存在D盘下!");
        }catch(e){
                alert("保存失败!");
        }
}