当前位置:首页 » 《随便一记》 » 正文

word预览方式---插件,vue-office-docx、docx-preview、mammoth.js

23 人参与  2024年11月07日 11:23  分类 : 《随便一记》  评论

点击全文阅读


提示:word预览方式—插件

文章目录

@[TOC](文章目录) 前言一、vue-office-docx二、docx-preview三、mammoth.js总结

前言

word预览

在这里插入图片描述

一、vue-office-docx

npm install vue-office-docx -S-D

officeDocx.vue

<template>    <div class="preview_box">      <VueOfficeDocx :src="htmlContent"></VueOfficeDocx>    </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

npm install docx-preview -S-D

docxPreview.vue

<template>    <div class="preview_box">       <div ref="docxPreviewRef"></div>    </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

npm install mammoth.js -S-D

docxMammoth.vue

<template>    <div class="preview_box">       <div ref="docxPreviewRef" v-html="htmlContent"></div>    </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>  

在这里插入图片描述
样式有问题,表格都没了

总结

踩坑路漫漫长@~@


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/183588.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • (番外)+(结局)陆州应清商(你是救赎亦是深渊全书+番外)_(陆州应清商)列表_笔趣阁(你是救赎亦是深渊全书+番外)
  • (番外)+(全书)(苏清离林墨宸)_离人未归,晚风不渡全书+后续列表_笔趣阁(苏清离林墨宸)(苏清离林墨宸)完结_(苏清离林墨宸)列表_笔趣阁(离人未归,晚风不渡全书+后续)
  • 全文蝴蝶梦结局+番外精选作品之一(闵暖季司凉)列表_全文蝴蝶梦结局+番外精选作品之一
  • 人间离别易多时,劝君勿相思+后续+结局(周明乾)列表_人间离别易多时,劝君勿相思+后续+结局(周明乾)人间离别易多时,劝君勿相思+后续+结局在线
  • 相思两别离悬念章节免费释出_「冉冉盛今安宋言心」最新后续章节在线阅读
  • 我给第三十八任老公过喜结局+番外(宋青青傅洛)列表_我给第三十八任老公过喜结局+番外(宋青青傅洛)全书+后续+结局在线
  • 水自无情舟渡人季铭穆婉结局+番外(季铭穆婉)_(水自无情舟渡人季铭穆婉结局+番外)列表_笔趣阁(季铭穆婉)
  • 我给第三十八任老公过喜全列表_我给第三十八任老公过喜全(宋青青聂子远)
  • 完结文玫瑰越过荆棘,苏清苒裴安煜免费+后续列表_完结文玫瑰越过荆棘,苏清苒裴安煜免费+后续
  • 全文他站在回忆尽头番外+结局(乔若兮沈辞安)列表_全文他站在回忆尽头番外+结局
  • (番外)+(全书)(岑时晏叶照绵)_叶照绵与岑时晏的+后续+结局列表_笔趣阁(岑时晏叶照绵)(岑时晏叶照绵)完结_(岑时晏叶照绵)列表_笔趣阁(叶照绵与岑时晏的+后续+结局)
  • [逆来顺受的妈妈]全文免费在线阅读_朋友明白独家章节限时试读

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1