Export HTML to Micorosoft Word Document and Download in the user workstation.
\
Install file-saver from node package manager.
·
Add Below code in your component file.
DownloadWord() {
//debugger;
var saveAs = require('file-saver');
//name of the
word document to export
var filename = "DocumentTest.doc";
//add styles to
the word document
var css = (
'<style>' +
'.Ecls {font-
size: 20px;color: #ff4400;}' +
'</style>'
);
//export the
template to the word document
var blob = new Blob(['\ufeff', css + this.GenerateHTML()], {
type: "application/msword;charset=utf-8"
});
saveAs(blob, filename);//save the word
}
//Generate the
HTML
GenerateHTML(): string {
var rawHtml = '';
rawHtml += '<table width="100%">'
rawHtml += '<tr><td class="Ecls"
colspan="1">This is Test</td></tr>'
rawHtml += '<tr><td></td><td></td></tr>'
rawHtml += '</table>';
return rawHtml;
}
No comments:
Post a Comment