解析上传的Excel文件以及对Excel里面的日期格式做处理

本文介绍了如何解析上传的Excel文件,并重点讲解了当Excel中包含自定义日期格式时,如何将解析出的数字转换为日期的方法。
摘要由CSDN通过智能技术生成

解析上传的Excel文件

<template>
  <div>
    <input ref="excel-upload-input" class="excel-upload-input" type="file" accept=".xlsx, .xls" @change="handleClick">
    <div class="drop" @drop="handleDrop" @dragover="handleDragover" @dragenter="handleDragover">
      将文件拖动到这里或点击
      <el-button :loading="loading" style="margin-left:16px;" size="mini" type="primary" @click="handleUpload">上传</el-button>
    </div>
  </div>
</template>

<script>
import XLSX from 'xlsx'

export default {
   
  props: {
   
    beforeUpload: Function, // eslint-disable-line
    onSuccess: Function// eslint-disable-line
  },
  data() {
   
    return {
   
      loading: false,

      excelData: {
   
        header: null,
        results: null,
        rawFile: null
      }
    }
  },
  methods: {
   
    generateData({
    header, results }) {
   
      this.excelData.header = header
      this.excelData.results = results
      this.onSuccess && this.onSuccess(this.excelData)
    },
    handleDrop(e) {
   
      e.stopPropagation()
      e.preventDefault()
      if (this.loading) return
      const files = e.dataTransfer.files
      if (files.length !== 1) {
   
        this.$message.error('Only support uploading one file!')
        return
      }
      const rawFile = files[0] // only use files[0]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值