首页 > 其他分享 >excel文件 —— array(导入)

excel文件 —— array(导入)

时间:2024-07-31 16:18:04浏览次数:7  
标签:const items excel else item 导入 attribute array type

/*导入*/
	let nodeData = ref()
	// 文件上传
	const uploadFile = function(file) {
		var groups = []
		// excel文件 —— array
		const reader = new FileReader();
		reader.readAsArrayBuffer(file.raw);
		reader.onload = function(e) {
			const data = new Uint8Array(e.target.result);
			const workbook = XLSX.read(data, {
				type: 'array'
			});
			const firstSheetName = workbook.SheetNames[0];
			const worksheet = workbook.Sheets[firstSheetName];
			const jsonData = XLSX.utils.sheet_to_json(worksheet);
			//去重
			let result = jsonData.filter((item, index, self) => {
				return self.findIndex(t => t.group === item.group) === index;
			});
			result.forEach(item => {
				groups.push({
					group: item.group,
					interval: item.interval,
					tags: []
				})
			})
			groups.forEach(item => {
				jsonData.forEach(items => {
					if(items.attribute == 'Read') {
						items.attribute = 1
					} else if(items.attribute == 'Write') {
						items.attribute = 2
					} else if(items.attribute == 'Read Write') {
						items.attribute = 3
					} else if(items.attribute == 'Subscribe') {
						items.attribute = 4
					} else if(items.attribute == 'Read Subscribe') {
						items.attribute = 5
					} else if(items.attribute == 'Write Subscribe') {
						items.attribute = 6
					} else if(items.attribute == 'Read Write Subscribe') {
						items.attribute = 7
					}
					if(items.type == 'INT16') {
						items.type = 3
					} else if(items.type == 'UINT16') {
						items.type = 4
					} else if(items.type == 'INT32') {
						items.type = 5
					} else if(items.type == 'UINT32') {
						items.type = 6
					} else if(items.type == 'INT64') {
						items.type = 7
					} else if(items.type == 'UINT64') {
						items.type = 8
					} else if(items.type == 'FLOAT') {
						items.type = 9
					} else if(items.type == 'DOUBLE') {
						items.type = 10
					} else if(items.type == 'BIT') {
						items.type = 11
					} else if(items.type == 'STRING') {
						items.type = 13
					} else if(items.type == 'BYTES') {
						items.type = 14
					}
					if(item.group == items.group) {
						item.tags.push(items)
					}
				})
			})
			importClick(groups)
		};
	}
	const importClick = function(groups) {
		importGtags({
			groups: groups,
			node: router.currentRoute.value.query.node,
		}).then(res => {
			if(res.status == 200) {
				ElMessage({
					type: 'success',
					message: '导入成功',
				})
				getListFun()
			} else {
				ElMessage({
					type: 'error',
					message: res.data.message,
				})
			}
		}).catch(err => {
			console.log(err);
		})
	}

  注意:

    记得安包XLSX 

    引用 import * as XLSX from 'xlsx'

标签:const,items,excel,else,item,导入,attribute,array,type
From: https://www.cnblogs.com/nengnengc-nnc/p/18334899

相关文章

  • Python:使用默认模块在python中读取excel
    我有Python2.6.6版本,但无法安装pandas、xlrd、xlwt等新模块。我想使用Python读取Excel。是否可以使用Python中存在的默认模块读取Excel。抱歉,不能使用Python2.6.6的默认模块读取Excel文件。Python没有内置的功能来处理Excel文件。使用外部库(如提......
  • 在Python中将简单的字典导出到Excel文件中
    我是Python新手。我有一个简单的字典,其键和值如下dict1={"numberofstoragearrays":45,"numberofports":2390,......}我需要将它们放入Excel表中,如下numberofstoragearrays45numberofports2390我有一个非常大的字典。importpandasasp......
  • Go--创建以当前时间命名的excel文件
    下载依赖包goget-ugithub.com/xuri/excelize/v2 代码packagemainimport("fmt""github.com/xuri/excelize/v2""time")funcmain(){//获取当前时间now:=time.Now()filename:=fmt.Sprintf("%s.xlsx&......
  • maven jar包 导入 添加 本地仓库 指定仓库 (mvn install:install-file)
    有时候会遇到将jar包导入本地仓库的需求。因为有些驱动包比较冷门,在公司的私服(远程仓库)里没有,为了在本地先跑起来,先添加到本地仓库。一、指定仓库执行命令: mvninstall:install-file-Dfile=D:\java\mavenData\xxxJdbcDriver2.jar-DgroupId=com.ali-DartifactId=xxx-jdbc......
  • C. Even Subarrays
    原题链接题解易得当区间异或和不为完全平方数的时候合法朴素做法:遍历所有区间,看看异或和是不是完全平方数优化:异或是可以交换运算顺序的,如果区间\([l,r]\)异或和为完全平方数,那么代表\(pre[r]\opluspre[l-1]==k\)其中k为完全平方数也就是说,\(pre[r]\oplusk==pre[l......
  • Vue3 - 最新详细实现网站内部打开预览 office 全套附件,在页面弹窗内解析预览 word文档
    前言如果您需要Vue2版本,请访问这篇文章。在vue3|nuxt3项目开发中,详解实现项目内部“打开解析预览各种office文档”通用预览插件,支持弹出一个窗口在弹框内预览或者直接显示在页面某个div容器里面,解析预览word文档、excel电子表格、ppt演示文稿、pdf文档、txt文......
  • Vue2 - 最新详细实现网站内部打开预览 office 全套附件,在页面弹窗内解析预览 word文档
    前言如果您需要Vue3版本,请访问在vue2|nuxt2项目开发中,详解实现项目内部“打开解析预览各种office文档”通用预览插件,解析预览word文档、excel电子表格、ppt演示文稿、pdf文档、txt文本等,支持弹出一个窗口在弹框内预览或者直接显示在页面某个div容器里面,让vue项......
  • Android开发 - (适配器)Adapter类中ArrayAdapter实现类详细解析
    作用将数组数据映射到UI组件(如ListView、Spinner等)上的角色。它是BaseAdapter的一个子类,专门用于处理简单的数据集合,如数组或列表。ArrayAdapter简化了数据到视图映射的过程,使得开发者能够以更少的代码实现数据的展示。它的主要作用为以下几点:数据绑定:它能够将一组数据......
  • 如何使用Python获取Excel文件中嵌入图像的位置?
    我正在使用包含嵌入图像的Excel文件(.xlsx)。我需要使用Python以编程方式提取这些图像的位置(单元格引用)。这是我到目前为止所尝试过的:任何建议将不胜感激。使用openpyxl和openpyxl-image-loader:我没有处理嵌入图像。解压缩Excel文件并检查内容:......
  • 如何在Google Colaboratory上导入并使用PyWhatKit?
    我想使用pywhatkit库自动从GoogleColab在WhatsApp上发送消息。到目前为止,我已经尝试过这样做:pipinstallpywhatkit输出:Requirementalreadysatisfied:pywhatkitin/usr/local/lib/python3.7/dist-packages(5.3)Requirementalreadysatisfied:wikipediain......