1.Angular 文件上传–》前端
<nz-upload [nzBeforeUpload]="noType" [nzFilter]="filters" >
<button nz-button [nzType]="'primary'" >确认</button>
</nz-upload>
/**
* 上传文件格式校验
*/
filters: UploadFilter[] = [
{
name: 'type',
fn: (fileList: UploadFile[]) => {
const filterFiles = fileList.filter(w => ~['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'].indexOf(w.type));
if (filterFiles.length !== fileList.length) {
this.msg.error(`包含文件格式不正确,只支持 excel 格式`);
return filterFiles;
}
return fileList;
}
}
];
//自定义文件上传
noType = (file: File): boolean => {
this.getExcelData(file)
return false;
}
//获取Excel数据
getExcelData(file: any) {
const formData = new FormData();
formData.append