简体   繁体   English

如何过滤primeng p-fileupload组件中的文件类型

[英]How to filter the file types in primeng p-fileupload component

I am trying to filter the file dialogue window using p-fileUpload from primeng.我正在尝试使用来自primeng的p-fileUpload过滤文件对话窗口。 I saw an example to to filter images as image/* and it works but i want ti filter for excel files.我看到了一个将图像过滤为 image/* 的示例,它可以工作,但我想要 ti 过滤 excel 文件。 I tried file/excel, file/*.xls etc, but no help.我尝试了文件/excel、文件/*.xls 等,但没有帮助。 Need help.需要帮忙。

Try below inputs with accept property in p-fileUpload in Angular在 Angular 的p-fileUpload中尝试使用接受属性的输入

  1. Image filter图像过滤器
    accept="image/*" [accepts all image file types] accept="image/*" [接受所有图像文件类型]
    accept="image/*.jpeg" [accepts only JPEG image file types] accept="image/*.jpeg" [仅接受 JPEG 图像文件类型]

  2. File filter文件过滤器
    accept="application/msexcel" [accepts only xls file types] accept="application/msexcel" [仅接受 xls 文件类型]
    accept=".xlsm,application/msexcel" [accepts only xls & xlsm file types] accept=".xlsm,application/msexcel" [仅接受 xls 和 xlsm 文件类型]
    accept="application/msmsword" [accepts only word file types] accept="application/msmsword" [仅接受 word 文件类型]

我们可以像这样按所需类型过滤

accept=".xlsx,.pdf,.csv,.xls"

.html .html

<p-fileUpload accept="{{acceptedFiles}}" invalidFileTypeMessageDetail="Sólo se permiten ficheros {{acceptedFiles}}"></p-fileUpload>

.ts .ts

 acceptedFiles: string = ".pdf, .jpg, .png, .doc, .docx, .xls, .xlsx, .csv";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM