HTML to DOCX in javascript with CSS

I’m a Programmer
Jul 22 · Unlisted
function export2Word() {var html, link, blob, url, css;css = (‘<style>’+whatever style you want’ +‘</style>’);html = document.getElementById(“id of content you want to generate as DOCX”).innerHTML;blob = new Blob([‘\ufeff’, css + html], {type: ‘application/msword’});url = URL.createObjectURL(blob);link = document.createElement(‘A’);link.href = url; = ‘Document’; // default name without extensiondocument.body.appendChild(link);if (navigator.msSaveOrOpenBlob ) navigator.msSaveOrOpenBlob( blob, ‘DocumentName.doc’); // IE10–11else; // other browsersdocument.body.removeChild(link);};
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade