导入excel到后台将数据添加到数据库

前台代码:

 <el-upload
      ref="upload"
      :action="uploadUrl()"
      :on-success="handleSuccess"
      :limit="1"
      :on-preview="handlePreview"
      :file-list="fileList"
      class="upload"
      multiple
      method:="post"
      accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,.csv">
      <el-button size="small" type="primary">选择文件</el-button>
      <div slot="tip" class="el-upload__tip"><i class="el-icon-warning" style="color:red;margin-right:5px"/>请上传excel格式,第一行为用户名,第二行为密码,第三行为小组名(默认为2)</div>
    </el-upload>


 uploadUrl() {
      var url = '../api/DynamicForm/RegisterForExcel'
      return url
    },
    handleSuccess(data) {
      if (data === 'success') {
        this.tip('注册成功!')
        this.$router.push({ path: 'adminUserManage', query: { t: +new Date() }})
      } else if (data === 'error') {
        this.errorTip('注册失败')
      }
      // 上传成功要处理的事
    },
    handlePreview() {
      // 上传前要处理的事
    },

后台代码:

public IHttpActionResult RegisterForExcel()
        {
            HttpFileCollection files = HttpContext.Current.Request.Files;
            try
   
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值