|
@@ -0,0 +1,69 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-upload
|
|
|
+ class="upload-demo"
|
|
|
+ action="https://jsonplaceholder.typicode.com/posts/"
|
|
|
+ :on-change="handleChange"
|
|
|
+ >
|
|
|
+ <el-button size="small" type="primary">点击上传</el-button>
|
|
|
+ </el-upload>
|
|
|
+
|
|
|
+ <el-table :data="tableData" style="width:100%">
|
|
|
+ <el-table-column
|
|
|
+ v-for="i in arr"
|
|
|
+ :key="i"
|
|
|
+ :prop="i"
|
|
|
+ :label="i"
|
|
|
+ width="180"
|
|
|
+ >
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import XLSX from "xlsx";
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ tableData: [{}],
|
|
|
+ arr: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ console.log();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleChange(file, fileList) {
|
|
|
+ const fileReader = new FileReader();
|
|
|
+ fileReader.onload = (ev) => {
|
|
|
+ try {
|
|
|
+ const data = ev.target.result;
|
|
|
+ const workbook = XLSX.read(data, {
|
|
|
+ type: "binary",
|
|
|
+ });
|
|
|
+ console.log(workbook);
|
|
|
+ let sheet = Object.keys(workbook.Sheets)[0];
|
|
|
+ const json = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]); //获得以第一列为键名的sheet数组对象
|
|
|
+ console.log(json);
|
|
|
+ var arr=[];
|
|
|
+ for (let v in json) {
|
|
|
+ if(v>100){break;}
|
|
|
+ for (let k in Object.keys(json[v])) {
|
|
|
+ if (arr.indexOf(Object.keys(json[v])[k]) == -1) {
|
|
|
+ arr.push(Object.keys(json[v])[k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.arr = arr
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.tableData = json;
|
|
|
+ });
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ fileReader.readAsBinaryString(file.raw);
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|