<template>
<div id="box">
<input type="file" id="fileInput" @change="handle($event)"/>
<evertComment v-for="item in comments" :content="item"></evertComment>>
</div>
</template>
<script setup lang='ts'>
import {ref} from 'vue'
import * as XLSX from "xlsx"
import evertComment from '../everyComment/index.vue'
import type { comments } from '../../type/components/tyep';
let ww:any=ref('')
let comments:any=ref([])
const handle=(event:any)=>{
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = async (e:any) => {
const data = e.target.result;
const workbook = XLSX.read(data, { type: 'binary' });
const sheetName = workbook.SheetNames[0];
const sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]);
// 在这里处理导入的数据
comments.value=JSON.stringify(sheetData.slice(0,10))
};
reader.readAsBinaryString(file);
}
}
</script>
vue+xlsx实现excel表格数据导入
最新推荐文章于 2024-07-23 16:38:24 发布