关于excel的导入功能:
.HTML 代码如下:
<div>
<input type="file" id="btn_file" style="display: none" (change)="importDishesExcls($event)" />
<button nz-button nzType="default" (click)="readExcel()">导入Excel</button>
</div>
.ts 代码如下:
importDishesExcls(evt) {
let filename = evt.target.files[0].name;
if (!filename.includes(".xls") && !filename.includes(".xlsx")) {
this.nzMessageService.info("文件类型不正确,只支持.xls,.xlsx格式");
(<HTMLInputElement>document.getElementById('btn_file')).value = ''
return;
}
let files = evt.target.files;
let formData = new FormData();
formData.append("file", files[0]);
this._CommonService.postList('/api/basic/examineInportDishExcel', formData).subscribe((res: any) => {
if(res.code==2000){
this.nzMessageService.success(res.msg);
}else{
this.nzMessageService.error(res.msg);
}
})
}