2017-02-23 116 views
2

enter image description here導出表,MS-Word中

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中,當我試圖再沒有顯示只是顯示數據

任何表結構和我用於新rollno分頁使用像<div style="page-break-after:always;">&nbsp;&nbsp;&nbsp;&nbsp;</div>這也不起作用

我的代碼有什麼問題?以及如何處理ms-word中的分頁符?

在此先感謝

回答

1

請嘗試這將工作

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

+0

我都嘗試將其與但表導出正確沒有問題結構不僅僅顯示內容世博會RT – Pravin