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

提示:word预览方式---插件

### 文章目录

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

前言

word预览

一、vue-office-docx

c 复制代码
npm install vue-office-docx -S-D

officeDocx.vue

c 复制代码
<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

c 复制代码
npm install docx-preview -S-D

docxPreview.vue

c 复制代码
<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

c 复制代码
npm install mammoth.js -S-D

docxMammoth.vue

c 复制代码
<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>
  

样式有问题,表格都没了

总结

踩坑路漫漫长@~@

相关推荐
琉璃℡初雪13 分钟前
vue2/3 中使用 @vue-office/docx 在网页中预览(docx、excel、pdf)文件
vue.js·pdf·excel
为美好的生活献上中指41 分钟前
java每日精进 5.11【WebSocket】
java·javascript·css·网络·sql·websocket·网络协议
拖孩2 小时前
【Nova UI】十五、打造组件库之滚动条组件(上):滚动条组件的起步与进阶
前端·javascript·css·vue.js·ui组件库
苹果电脑的鑫鑫2 小时前
element中表格文字剧中可以使用的属性
javascript·vue.js·elementui
Hejjon2 小时前
Vue2 elementUI 二次封装命令式表单弹框组件
前端·vue.js
一丝晨光3 小时前
数值溢出保护?数值溢出应该是多少?Swift如何让整数计算溢出不抛出异常?类型最大值和最小值?
java·javascript·c++·rust·go·c·swift
Wannaer3 小时前
从 Vue3 回望 Vue2:响应式的内核革命
前端·javascript·vue.js
懒羊羊我小弟4 小时前
手写符合Promise/A+规范的Promise类
前端·javascript
赵大仁4 小时前
React vs Vue:点击外部事件处理的对比与实现
javascript·vue.js·react.js
肥肥呀呀呀5 小时前
在Flutter上如何实现按钮的拖拽效果
前端·javascript·flutter