vue+springboot导入Excel表格

1.创建一个excel表格,与数据库需要的表头对应

2.(前端)导入excel的按钮
复制代码
<template class="importExcel">
  <el-button type="primary"  @click="chooseFile">导入<i class="el-icon-upload el-icon--right"></i></el-button>
  <input type="file" ref="fileInput" style="display: none"
         @change="handleFileChange" accept=".xlsx, .xls" />
</template>

显示为这样

3.按钮涉及到的方法
javascript 复制代码
chooseFile() {
  this.$refs.fileInput.click();
},
handleFileChange(event) {
  const file = event.target.files[0];
  if (file) {
    this.$message('所选文件:' + file.name);
    const fData = new FormData();
    fData.append('fData', file);
    const 
    axios.post("http://localhost:8081/probationaryPartyMember/importExcel", fData).then((response) => {
      console.log(response.data);
      if(response.data.code === 1) {
        // 处理成功响应
        this.$message('文件上传成功', response);
        this.formInline.name = '';
        this.formInline.studentId = '';
        this.formInline.reply = '';
        this.getList();
      }else {
        if (response.data.data === 2) {
          this.$message("编号为" + response.data.data + "的预备党员已存在,请删除这条数据上传之后的数据");
          if (response.data.data === 0) {
            this.$message("申请编号为" + response.data.data + "及之后的数据上传失败");
          }
        }
      }
    }).catch((error) => {
          // 处理错误
          console.error('文件上传失败', error);
          // 显示一个友好的错误消息给用户
          this.$message.error('文件上传失败,请检查文件并重试');
        });
  }


},
4 . (后端) 导入依赖
java 复制代码
 <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>3.1.1</version>
        </dependency>
5.创建一个实体类
6.创建一个类,继承ReadListener接口
7.在其他类中调用上述方法
8.得到列表,进行后续操作
相关推荐
光依旧37 分钟前
MCP实战手记系列(十):MCP Server高可用实战
spring boot·高可用·nginx负载均衡·redis哨兵·mcp·微服务容错·resilience4j熔断
志尊宝2 小时前
Vue3 零基础每日笔记(073):keep-alive 页面缓存实战——列表页返回不丢状态
vue.js·笔记·缓存·#vue #前端 #前端开发·#javascript·#vue.js
优选资讯3 小时前
标签打印软件怎么对接 Excel 数据
前端·excel
省钱兄--zs4 小时前
西安24小时自助健身房解决方案实战:系统开发与部署全流程指南
java·spring boot·系统架构·intellij-idea·需求分析
ly76896 小时前
Spring Boot 集成 Elasticsearch 的生产实践:客户端选型、索引生命周期与批量写入容错
spring boot·elasticsearch·索引生命周期·java api client·批量写入
程序猿_极客6 小时前
【免费】分享一套优质的基于SpringBoot的服装商城管理系统的设计与实现(带可视化图表、协同过滤功能),源码+文档+视频详解(讲解)
java·spring boot·后端·服装商城管理系统
泡海椒6 小时前
JQuick-Excel 实战:FORMAT 管理日期与数字的 Excel 显示
开发语言·python·excel
bug菌7 小时前
🤔同事突然问我:Spring的注解 @Component 和 @Service 有何不同?
java·spring boot·后端
AIGS0017 小时前
从814张表到250个本体:本体建模在做什么
数据库·excel·erp·数据中台·智能问数·本体语义·企业大脑
Lonely丶墨轩7 小时前
用 Vue + Spring Boot + Python 做一个 AI 双人海龟汤游戏:从出题、联机到自动审稿等核心技术设计与实现
spring boot·后端·游戏