上传excel文件
格式1:
<input type="file" class="hidden" #uploadDataFileInput accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
(change)="doUploadDataFile()" />
<button (click)="uploadDataFileInput.click()">
</button>
格式2:
html:
<input type="file" class="hidden" #uploadSubjectFileInput accept=".xlsx"
(change)="handleUploadFile($event)" />
ts:
/** 隐藏的文件控件对象 */
@ViewChild('uploadSubjectFileInput')
uploadSubjectFileInput!: ElementRef;
handleUploadFile(event: any) {
// 解析excel文件
this.processSubjectExcel();
// 允许相同文件上传
event.target.value = '';
}
private processSubjectExcel() {
const fileList = this.uploadSubjectFileInput.nativeElement.files;
if (!fileList || fileList.length === 0) return;
}
// 批量上传
uploadSubjectFileBtn() {
// 解析excel文件
this.uploadSubjectFileInput.nativeElement.click();
}
浙公网安备 33010602011771号