xlsx库插件读取excel文件

news/2024/9/28 20:58:28/

input读取xlsx文件内容

  • 效果
  • 代码

前端用input读取 .xlsx文件的内容
xlsx库参考连接

项目中我用的ant-design-vue,不过用input一样的大同小异
注意区分xlsx库和node-xlsx库的使用环境

效果

在这里插入图片描述
在这里插入图片描述

代码

typescript"><!--* @Descripttion: * @Author: 苍狼一啸八荒惊* @Date: 2024-08-18 18:08:51* @LastEditTime: 2024-09-27 09:34:04* @LastEditors: 一苇以航
-->
<script lang="ts" setup>
// import XLSX from 'node-xlsx';
import * as XLSX from 'xlsx/xlsx.mjs';
const data = reactive({ fileList: [], loading: false });const customUpload = (info: any) => {data.loading = true;//文件后缀名// let suffixName = info.file.name.split('.').pop();let fileReader = new FileReader();fileReader.readAsArrayBuffer(info.file);fileReader.onload = function (e: any) {const data = new Uint8Array(e.target.result);const workbook = XLSX.read(data, { type: 'array' });// 假设我们只读取第一个工作表const firstSheetName = workbook.SheetNames[0];//所有工作表名称// console.log(workbook.SheetNames);//所有工作表数据 需要用XLSX.utils.sheet_to_json(worksheet, { header: 1 });转换成数组格式// console.log(workbook.Sheets);const worksheet = workbook.Sheets[firstSheetName];const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });// console.log(jsonData);// 将JSON数据转换成文本let text = JSON.stringify(jsonData);// console.log(text);};data.loading = false;
};
</script>
<template><Header /><div class="main-container"><a-card class="mt-20" title="样本管理"><template #extra><a-space><a-uploadv-model:file-list="data.fileList":customRequest="customUpload"accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"name="file":multiple="false":showUploadList="false"><a-button :loading="data.loading" type="primary">导入文件</a-button></a-upload></a-space></template></a-card></div>
</template><style lang="less" scoped></style>

http://www.ppmy.cn/news/1531616.html

相关文章

网页爬虫法律与道德:探索法律边界与道德规范

目录 引言 一、网络爬虫技术概述 1.1 定义与功能 1.2 技术原理 1.3 案例分析 二、网络爬虫的法律边界 2.1 合法性要求 2.2 刑事风险 2.3 案例分析 三、网络爬虫的道德规范 3.1 尊重版权和隐私 3.2 合理使用爬虫技术 3.3 透明度和社会责任 四、技术挑战与应对策略…

netty之Future和Promise

结构 #mermaid-svg-CVCnLB2sqPPK8Gn2 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-CVCnLB2sqPPK8Gn2 .error-icon{fill:#552222;}#mermaid-svg-CVCnLB2sqPPK8Gn2 .error-text{fill:#552222;stroke:#552222;}#merm…

Karmada新版本发布,支持联邦应用跨集群滚动升级

摘要&#xff1a;本次升级支持联邦应用跨集群滚动升级&#xff0c;使用户版本发布流程更加灵活可控&#xff1b;透明同事karmadactl 新增了多项运维能力&#xff0c;提供独特的多集群运维体验。 本文分享自华为云社区 《Karmada v1.11 版本发布&#xff01;新增应用跨集群滚动升…

初始MYSQL数据库(6)—— 事务

找往期文章包括但不限于本期文章中不懂的知识点&#xff1a; 个人主页&#xff1a;我要学编程(ಥ_ಥ)-CSDN博客 所属专栏&#xff1a; MYSQL 目录 事务的概念 事务的ACID特性 使用事务 查看支持事务的存储引擎 事务的语法 保存点 自动/手动提交事务 事务的隔离性和…

uni-app 封装websocket 心跳检测,开箱即用

class websocketUtils {constructor(url, needbeat, options {}) {this.needbeat needbeat;this.url url;this.options options;this.ws null;this.heartbeatInterval options.heartbeatInterval || 10000; // 心跳间隔&#xff0c;默认为10秒 this.reconnectInterval …

SPI驱动学习七(SPI_Slave_Mode驱动程序框架)

目录 一、SPI_Slave_Mode驱动程序框架1. Master和Slave模式差别1.1 主设备 (Master)1.2 从设备 (Slave)1.3 示例 2. SPI传输概述2.1 数据组织方式2.2 SPI控制器数据结构 3. SPI Slave Mode数据传输过程4. 如何编写程序4.1 设备树4.2 内核相关4.3 简单的示例代码4.3.1 master和s…

【每日刷题】Day133

【每日刷题】Day133 &#x1f955;个人主页&#xff1a;开敲&#x1f349; &#x1f525;所属专栏&#xff1a;每日刷题&#x1f34d; &#x1f33c;文章目录&#x1f33c; 1. LCR 085. 括号生成 - 力扣&#xff08;LeetCode&#xff09; 2. LCR 102. 目标和 - 力扣&#xff…

sqlalchemy时区问题

问题描述 sqlalchemy查询时间字段时&#xff08;包含timestamp&#xff09;&#xff0c;查询到python中使用datetime类型接收&#xff0c;不会进行时区类型转换&#xff0c;如果你的机器时区跟数据库时区不一致&#xff0c;就会导致比较时间时出问题。 解决方案 一般镜像默认…