前端导入Excel表格获取数据(Vue3+TS+Element)

本文介绍了如何在ElementPlus的上传组件中实现文件上传,重点讲解了如何处理上传的Excel文件,包括读取、解析为二进制格式并转化为JSON数据的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <el-upload
    ref="upload"
    class="upload-demo"
    :limit="1"
    :on-exceed="handleExceed"
    :show-file-list="false"
    action
    accept=".xlsx,.xls"
    :auto-upload="false"
    :on-change="handleChange"
  >
    <template #trigger>
      <el-button type="primary" :icon="Download" plain>导入</el-button>
    </template>
  </el-upload>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { genFileId } from 'element-plus'
import { Download } from '@element-plus/icons-vue'
//excel文件数据解析
import * as XLSX from 'xlsx'
import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus'

const upload = ref<UploadInstance>()

const handleExceed: UploadProps['onExceed'] = (files) => {
  upload.value!.clearFiles()
  const file = files[0] as UploadRawFile
  file.uid = genFileId()
  upload.value!.handleStart(file)
}

interface tableConfigType {
  nam
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值