首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

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

2013-02-28 
js导出html页面到word中的问题求解function AllAreaWord(){ var oWD new ActiveXObject(Word.Applicati

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("保存失败!");
        }
}

热点排行