javascriptはHTMLをword,pdfなど(ie)に変換します.

3008 ワード

/**
 * @author wsf html    
 */

var filePath = "d:";

function exportHtml() {
    if (filePath != null) {
        var file;
        try {
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            file = fso.createtextfile(filePath + "/    .html", true); //     
            file.WriteLine(content.innerHTML); //     
            alert("    ");
        } catch(e) {
            alert("    ");
        } finally {
            if (file != null) file.close(); //     
        }
    }
}

function exportWord() {
    if (filePath != null) {
        try {
            var word = new ActiveXObject("Word.Application");
            var doc = word.Documents.Add("", 0, 1);
            var range = doc.Range(0, 1);
            var sel = document.body.createTextRange();
            try {
                sel.moveToElementText(content);
            } catch(notE) {
                alert("      ,        。");
                window.close();
                return;
            }
            sel.select();
            sel.execCommand("Copy");
            range.Paste();
            // word.Application.Visible = true;//   word      
            doc.saveAs(filePath + "/    .doc"); //   
            alert("    ");
        } catch(e) {
            alert("      ,         Microsoft Office Word(    ),           ,   IE   ActiveX  。");
        } finally {
            try {
                word.quit()
            } catch(ex) {}
        }
    }
}

function exportPdf() {
    if (filePath != null) {
        try {
            var word = new ActiveXObject("Word.Application");
            var doc = word.Documents.Add("", 0, 1);
            var range = doc.Range(0, 1);
            var sel = document.body.createTextRange();
            try {
                sel.moveToElementText(content);
            } catch(notE) {
                alert("      ,        。");
                window.close();
                return;
            }
            sel.select();
            sel.execCommand("Copy");
            range.Paste();
            // word.Application.Visible = true;//   word      
            doc.saveAs(filePath + "/    .pdf", 17); //    pdf  
            alert("    ");
        } catch(e) {
            alert("      ,         Microsoft Office Word 2007    ,           ,   IE   ActiveX  。");
        } finally {
            try {
                word.quit()
            } catch(ex) {}
        }
    }
}