javascript - 将表格导出到 MS-Word

标签 javascript angularjs

enter image description here

function export2Word() {

    var html, link, blob, url, css;

    css = (
               '<style>  table {   border-collapse: collapse;  border-style:none;  } .tables td,th{border:1px solid black;}' +
               //'@page WordSection1{size: 841.95pt 595.35pt;mso-page-orientation: landscape;}' +
               //'div.WordSection1 {page: WordSection1;} ' +
               '</style>'
             );

     html = document.getElementById("tblPrint").outerHTML;
     blob = new Blob(['\ufeff', css + html], {
                 type: 'application/msword'
             });
     url = URL.createObjectURL(blob);
     link = document.createElement('A');
     link.href = url;
     link.download = 'Document';  // default name without extension 
     document.body.appendChild(link);
     if (navigator.msSaveOrOpenBlob) 
         navigator.msSaveOrOpenBlob(blob, 'Document.doc'); // IE10-11
     else link.click();  // other browsers
         document.body.removeChild(link);
};

我想在尝试时将表格导出到 MS-Word 然后不显示任何表格结构只显示数据

并且我使用像 <div style="page-break-after:always;">&nbsp;&nbsp;&nbsp;&nbsp;</div> 这样的新 rollno 分页符这也不起作用

我的代码有什么问题?以及如何处理 ms-word 中的分页符?

提前致谢

最佳答案

请尝试这会起作用

export html table as word file

var docDOM = document.getElementById('example');

var docObject = docx.export(docDOM, // required DOM Object
{
creator: "Creator", // optional String
lastModifiedBy: "Last person to modify", // optional String
created: new Date(), // optional Date Object
modified: new Date() // optional Date Object
});

var link = document.createElement('a');
link.appendChild(document.createTextNode("Download Link Text"));
link.title = "Download Title";
link.download = "FilenameHere.docx";
link.href = docObject.href();
document.getElementById("example").appendChild(link);

convert html table to word

关于javascript - 将表格导出到 MS-Word,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42406772/

相关文章:

javascript - 单击按钮时无法阻止网页发布

javascript - 错误 : Enzyme Internal Error: unknown composite type undefined

javascript - 如何在每次 View 更改时触发 AngularJS 指令?

angularjs - 如何以 Angular 将值从一条路线传递到另一条路线?

css - ng-enter-stagger 动画不适用于 safari

javascript - fullCalendar Jquery 插件未出现在页面上

javascript - 折叠父节点直到 mouseout 它的子节点

javascript - 如何获取组件的滚动位置?

javascript - AngularJS promise 捕获 401

javascript - AngularJS 在某些情况下覆盖服务注入(inject)