在vue3中实现pptx、word、excel预览

插件推荐

PPTXjs
vue-office

代码

html 复制代码
<script setup lang="ts" name="home">
import { computed, nextTick, ref, onMounted } from 'vue';
//引入VueOfficeDocx组件
import VueOfficeDocx from '@vue-office/docx';
//引入VueOfficeExcel组件
import VueOfficeExcel from '@vue-office/excel';
//引入相关样式
import '@vue-office/docx/lib/index.css';
const docx = ref('/file/test.docx'); //设置文档网络地址,可以是相对地址
const excel = ref('/file/test.xlsx'); //设置excel网络地址,可以是相对地址
const pptx = ref('/file/test.pptx'); //设置ppt网络地址,可以是相对地址

const renderedHandler = () => {
  console.log('渲染完成');
};
const errorHandler = () => {
  console.log('渲染失败');
};
</script>

<template>
  <div>
    <h1>PPT文档预览</h1>
    <iframe :src="`/PPTXjs-1.21.1/index.html?file=` + pptx" width="100%" height="900" frameborder="0"></iframe>
    <h1>word文档预览</h1>
    <vue-office-docx :src="docx" style="width: 100%; height: 900px" @rendered="renderedHandler" @error="errorHandler" />
    <h1>excel预览</h1>
    <vue-office-excel
      :src="excel"
      style="width: 100%; height: 900px"
      @rendered="renderedHandler"
      @error="errorHandler"
    />
  </div>
</template>

<style scoped></style>

pptxjs 文件传递

需要在 index.html 中获取文件地址

相关推荐
嘻嘻哈哈猿人15 小时前
从 0 到 1 实现一个支持 @ 提及用户的输入框组件(Vue3 实战)
前端·vue.js
云枫晖15 小时前
Vue3 响应式原理:手写实现 ref 函数
前端·vue.js
hachi031316 小时前
Vue中input disabled时点击事件不触发怎么办?
javascript·vue.js·ecmascript
BestSongC16 小时前
基于VUE和FastAPI的行人目标检测系统
vue.js·人工智能·yolo·目标检测·fastapi
起名时在学Aiifox16 小时前
Vue3 + Element Plus 表格排序实战:基于状态字段的智能排序方案
前端·javascript·vue.js·element plus
傻啦嘿哟16 小时前
Python将Excel工作表转换为PDF:从入门到实战
python·pdf·excel
鹤鸣的日常17 小时前
Vue + element plus 二次封装表格
前端·javascript·vue.js·elementui·typescript
北慕阳17 小时前
速成Vue,自己看
前端·javascript·vue.js
罗政18 小时前
WPS Excel快速进行同表内的单元格差异对比(高亮)
excel·wps
小禾青青18 小时前
我用uniapp开发app用到的uniapp插件
前端·vue.js·uni-app