Ticker

6/recent/ticker-posts

vuejs export html to word javascript

<div id="app">
<textarea v-model="word" ref="word" name="text" id="text" cols="30" rows="10"></textarea>
<button @click="exportHTML">Export as Word</button>
</div>
view raw index.html hosted with ❤ by GitHub
new Vue({
data(){
return{
word: ''
}
},
methods:{
exportHTML(){
var vm = this, word = `<html xmlns:o='urn:schemas-microsoft-com:office:office xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head><meta charset='utf-8'><title>Export HTML to Word Document with JavaScript</title></head><body>${vm.word}</body></html>`;
var source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(word);
var fileDownload = document.createElement("a");
document.body.appendChild(fileDownload);
fileDownload.href = source;
fileDownload.download = 'document.doc';
fileDownload.click();
document.body.removeChild(fileDownload);
}
}
}).$mount('#app')
view raw script.js hosted with ❤ by GitHub
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
view raw scripts hosted with ❤ by GitHub

Post a Comment

1 Comments

Textool said…
Your post is providing some really good information. I liked its essence and enjoyed reading it. Keep sharing such important posts about this blog and its much more helpful for us . Word frequency counter