|
@@ -0,0 +1,38 @@
|
|
|
+<template>
|
|
|
+ <table>
|
|
|
+ <tr v-for="(row, index) in excelData" :key="index">
|
|
|
+ <td v-for="(cell, cellIndex) in row" :key="cellIndex">{{ cell }}</td>
|
|
|
+ </tr>
|
|
|
+ </table>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <script>
|
|
|
+// import XLSX from 'xlsx'; // 确保正确导入
|
|
|
+ const XLSX = require('xlsx');// 用const的方式才行
|
|
|
+ export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ fileUrl: null,
|
|
|
+ fileName: null,
|
|
|
+ excelData: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ async loadExcel(file) {
|
|
|
+ const arrayBuffer = await file.arrayBuffer();
|
|
|
+ const workbook = XLSX.read(arrayBuffer, { type: 'array' });
|
|
|
+ const sheetName = workbook.SheetNames[0];
|
|
|
+ const sheet = workbook.Sheets[sheetName];
|
|
|
+ this.excelData = XLSX.utils.sheet_to_json(sheet, { header: 1 });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.fileUrl = sessionStorage.getItem("fileUrl");
|
|
|
+ this.fileName = sessionStorage.getItem("fileName");
|
|
|
+ // 示例:加载一个 .xlsx 文件
|
|
|
+ fetch(this.fileUrl)
|
|
|
+ .then((response) => response.blob())
|
|
|
+ .then((blob) => this.loadExcel(blob));
|
|
|
+ },
|
|
|
+ };
|
|
|
+ </script>
|