export page to microsoft word in Angular.js

علی ذوالفقار
1401/02/05 13:38:57 (332)
    $scope.exportWord = function () {
        var html = angular.element(document.querySelector('#data'))[0].innerHTML;
        var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' " +
            "xmlns:w='urn:schemas-microsoft-com:office:word' " +
            "xmlns='http://www.w3.org/TR/REC-html40'>" +
            "<head><meta charset='utf-8'><title>Export Table to Word</title></head><body>";
        var footer = "</body></html>";
        var sourceHTML = header + "<table border='1' cellpadding='1' cellspacing='1' dir='rtl'>" + html + "</table>" + footer;
        if (navigator.msSaveBlob) { // IE 10+
            navigator.msSaveBlob(new Blob([sourceHTML], { type: 'application/vnd.ms-word' }), $scope.info.coname + ".doc");
        } else {
            var source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML);
            var fileDownload = document.createElement("a");
            document.body.appendChild(fileDownload);
            fileDownload.href = source;
            fileDownload.download = $scope.info.coname +'.doc';
            fileDownload.click();
            document.body.removeChild(fileDownload);
        }
    }

Back