vue-office:word(.docx)、pdf、excel(.xlsx,.xls)格式文件预览

vue-office:word(.docx)、excel(.xlsx,.xls)格式文件预览

组件安装
bash 复制代码
// docx文档预览组件
npm install @vue-office/docx [email protected]

// excel文档预览组件
npm install @vue-office/excel [email protected]

// pdf文档预览组件
npm install @vue-office/pdf [email protected]

注意:如果是vue2.6版本或以下还需要额外安装 @vue/composition-api,不然会报错

bash 复制代码
npm install @vue/composition-api --save
引用使用

docx

html 复制代码
<template>
 <div class="dashboard-container">
    <el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button>

    <el-dialog
      title="docx文件预览"
      :visible.sync="dialogVisible"
      width="60%">
      <VueOfficeDocx :src="url" style="height: 60vh;" @rendered="rendered"></VueOfficeDocx>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
//引入VueOfficeDocx组件
import VueOfficeDocx from '@vue-office/docx'
//引入相关样式
import '@vue-office/docx/lib/index.css'

export default {
    components:{
        VueOfficeDocx
    },
    data(){
        return {
            url: 'eee.docx' //设置文档网络地址,或者相对地址
        }
    },
    methods: {
        rendered(){
            console.log("渲染完成")
        }
    }
}
</script>

xlsx xls

html 复制代码
<VueOfficeExcel :src="url" style="height: 60vh;" :options="options" @rendered="renderedHandler"
        @error="errorHandler"></VueOfficeExcel>
html 复制代码
<script>
//引入VueOfficeExcel组件
import VueOfficeExcel from '@vue-office/excel'
//引入相关样式
import '@vue-office/excel/lib/index.css'
    export default {
    components: {
        VueOfficeExcel
    },
    data() {
        return {
            excel: 'eee.xlsx'//设置文档地址,
            options: {
                xls: true //设为true,可预览xls
            }
        }
    },
    methods: {
        renderedHandler() {
            console.log("渲染完成")
        },
        errorHandler() {
            console.log("渲染失败")
        }
    }
}
</script>
相关推荐
john_Asura4 小时前
Vue 前端全方位性能优化指南
前端·vue.js·性能优化
xzdangelliu5 小时前
POI模板生成EXCEL 64000 style in a .xlsx Workbook
java·excel·poi
编程乐趣5 小时前
推荐一个Excel与实体映射导入导出的C#开源库
开源·c#·.net·excel
Bonnie_12155 小时前
05-jenkins学习之旅-vue前项目部署实践
vue.js·学习·jenkins
格调UI成品6 小时前
React vs Vue.js:选哪个框架更适合你的项目?
前端·vue.js·react.js
BillKu7 小时前
Vue3监听对象数组属性变化方法
javascript·vue.js·ecmascript
zheshiyangyang9 小时前
使用Vue3制作一款个性化上传组件
前端·javascript·vue.js
碧海蓝天go星辰大海11 小时前
word如何右对齐封面中个人信息下的下划线
word
GIS之家11 小时前
vue+cesium示例:3Dtiles三维模型高度调整(附源码下载)
前端·vue.js·3d·cesium·webgis
徐赛俊11 小时前
Word VBA 教程|一键将 PNG/JPG 图片插入每一页(浮于文字上方,固定大小)
开发语言·c#·word