XSLX,如何读取,并解析excel中的内容,图片可以解析吗?

2023-06-30 270 0

image.png
XSLX,如何读取,并解析excel中的内容?打印出并不包含图片内容?

<template>
  <el-upload
    ref="xlsx-upload"
    class="xlsx-upload"
    action=""
    :auto-upload="false"
    :file-list="fileList"
    :on-change="handleChange"
    :multiple="false"
    :show-file-list="false"
  >
    <el-button type="primary" size="small" plain>点击上传</el-button>
  </el-upload>
</template>
<script lang="ts">
import { Component, Vue, Watch } from "vue-property-decorator";
import XLSX from "xlsx";
@Component({})
export default class BulkImport extends Vue {
  fileList: any = [];
  file: any = "";
  /* --- --- 方法区域  --- --- */
  handleChange(file: any, fileList: any) {
    console.log("更新------", file, "bbbbbbbbb", fileList);
    this.fileList = [fileList[fileList.length - 1]]; //只能上传一个`Excel`,重复上传会覆盖之前的
    this.file = file.raw;
    const reader = new FileReader();
    reader.readAsArrayBuffer(this.file);
    reader.onload = () => {
      const buffer: any = reader.result;
      const bytes = new Uint8Array(buffer);
      const length = bytes.byteLength;
      let binary = "";
      for (let i = 0; i < length; i++) {
        binary += String.fromCharCode(bytes[i]);
      }
      const wb = XLSX.read(binary, { type: "binary", cellDates: true }); //cellDates,设置为true,将天数的时间戳转为时间格式
      const outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);
      console.log("outdata", outdata);
    };
  }
}
</script>

image.png

看看这个库:https://github.com/exceljs/exceljs/blob/master/README_zh.md

回答

相关文章

nuxt2部署静态化和ssr的时候访问首页先报404再出现首页为什么?
`clip-path` 如何绘制圆角平行四边形呢?
多线程wait方法报错?
VUE 绑定的方法如何直接使用外部函数?
vue2固定定位该怎么做?
谁有redis实现信号量的代码,希望借鉴一下?