word预览方式---插件,vue-office-docx、docx-preview、mammoth.js
longlongago~~ 2024-09-09 16:35:01 阅读 86
提示:word预览方式—插件
文章目录
@[TOC](文章目录)
前言一、vue-office-docx二、docx-preview三、mammoth.js总结
前言
word预览
一、vue-office-docx
<code>npm install vue-office-docx -S-D
officeDocx.vue
<template>
<div class="preview_box">code>
<VueOfficeDocx :src="htmlContent"></VueOfficeDocx>code>
</div>
</template>
<script>
import axios from 'axios'
import VueOfficeDocx from '@vue-office/docx'
//引入相关样式
import '@vue-office/docx/lib/index.css';
export default { -- -->
name: 'preview',
components:{ VueOfficeDocx},
data () {
return {
src:`.docx文件rul`,
htmlContent:''
}
},
mounted(){
this.docToHtml();
},
methods: {
docToHtml(){
axios.get(this.src,{ responseType: 'arraybuffer' }).then((res)=>{
this.htmlContent = res.data;
})
}
}
}
</script>
<style scoped></style>
样式还原度一般,间距太大,分页也有问题
二、docx-preview
<code>npm install docx-preview -S-D
docxPreview.vue
<template>
<div class="preview_box">code>
<div ref="docxPreviewRef"></div>code>
</div>
</template>
<script>
import axios from 'axios'
import { -- --> renderAsync } from 'docx-preview'
export default {
name: 'preview',
components:{ },
data () {
return {
src:`.docx文件rul`,
}
},
mounted(){
this.docToHtml();
},
methods: {
docToHtml(){
axios.get(this.src,{ responseType: 'arraybuffer' }).then((res)=>{
renderAsync(res.data, this.$refs.docxPreviewRef);
})
}
}
}
</script>
<style scoped></style>
样式还原度一般,无分页
三、mammoth.js
<code>npm install mammoth.js -S-D
docxMammoth.vue
<template>
<div class="preview_box">code>
<div ref="docxPreviewRef" v-html="htmlContent"></div>code>
</div>
</template>
<script>
import axios from 'axios'
import mammoth from 'mammoth'
export default { -- -->
name: 'preview',
components:{ },
data () {
return {
src:`.docx文件rul`,
htmlContent:''
}
},
mounted(){
this.docToHtml();
},
methods: {
docToHtml(){
axios.get(this.src,{ responseType: 'arraybuffer' }).then((res)=>{
mammoth.convertToHtml({ arrayBuffer: new Uint8Array(res.data) }).then((html)=>{
this.htmlContent = html.value;
})
})
}
}
}
</script>
<style scoped></style>
样式有问题,表格都没了
总结
踩坑路漫漫长@~@
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。