2026-04-10 08:42:59 +08:00
|
|
|
|
<template>
|
2026-04-11 15:36:50 +08:00
|
|
|
|
<div class="xlsx-preview" :style="{ height: height }">
|
2026-04-10 08:42:59 +08:00
|
|
|
|
<vue-office-excel :src="src" @render-error="handleExcelError" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import VueOfficeExcel from '@vue-office/excel';
|
|
|
|
|
|
import '@vue-office/excel/lib/index.css';
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: "XlsxPreview",
|
|
|
|
|
|
components: {
|
|
|
|
|
|
VueOfficeExcel
|
|
|
|
|
|
},
|
|
|
|
|
|
props: {
|
|
|
|
|
|
src: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
description: "Excel文件的URL或路径"
|
2026-04-11 15:36:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
height: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
default: "70vh",
|
|
|
|
|
|
description: "预览区域高度"
|
2026-04-10 08:42:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
handleExcelError(err) {
|
|
|
|
|
|
console.error('excel预览失败:', err);
|
|
|
|
|
|
this.$message.error('Excel预览失败,请下载查看');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.xlsx-preview {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|