angular 上传Excel

import { FileUploader } from 'ng2-file-upload';

this.uploader = new FileUploader({
      url: this.importExcelUrl,
      method: 'POST',
      itemAlias: 'excel',
    });

 
 // 选择的文件
 selectedFileOnChanged (item) {
      console.log(item);
 }
 // 上传文件,这里是全部上传
 fileAllUp () {
    this.uploader.uploadAll();
    this.uploader.queue[0].onSuccess = (response, status, headers) => {
      // 上传文件成功
      if (response['status'] == 'ok') {
        this.dataTips = '上传成功 ! -----' + response['message'];
      }else {
        this.dataTips = '上传失败 ! -----' + response['message'];
      }
    }
}

  // 清空选择列表
 fileAllDelete (): any {
    this.uploader.clearQueue();
}

<input type="file" id="fileInput" ng2FileSelect [uploader]="uploader" (change)="selectedFileOnChanged($event)" multiple />

<h5>文件数量:  {{ uploader?.queue?.length }}</h5>    

<table>
    <thead>
      <tr>
        <th>名称</th>
        <th>大小</th>
        <th>状态</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody >
      <tr *ngFor="let item of uploader.queue">
        <td><strong>{{ item?.file?.name }}</strong></td> <!--文件名-->
        <td><strong>{{ item?.file?.size/1024/1024 | number:'.2' }} MB</strong></td>
        <td class="tableth">
          <span *ngIf="item.isSuccess">成功</span>
          <span *ngIf="!item.isUploaded">未上传</span>
          <span *ngIf="item.isError">错误</span>
        </td>
        <td>
          <button class="btn btn-danger btn-sm" (click)="item.remove()">删除</button>
        </td>
      </tr>
    </tbody>
  </table>

<button class="btn btn-primary" (click)="fileAllUp()" >全部上传</button>
<button class="btn btn-danger"  (click)="fileAllDelete()" >清除列表</button>
headers       ----->  上传文件的请求头参数
method        ----->  上传文件的方式
maxFileSize   ----->  最大可上传文件的大小
url           ----->  地址
itemAlias     ----->  文件别名
progress      ----->  上传进度


cancel()      ----->  取消上传
upload()      ----->  上传文件


附加参数
1 additionalParameter: {}
2 this.ouloader.setOptions( {} )

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值