Reputation: 1363
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);
};
I want to export table to MS-Word when I tried then not showing any table structure just showing data
and I used page break for new rollno using like <div style="page-break-after:always;"> </div>
this also not working
what is wrong in my code? and what to do for page break in ms-word?
Thanks in advance
Upvotes: 2
Views: 6845
Reputation: 11
please try this will work
export html table as word file
or
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);
Upvotes: 1