简体   繁体   English

如何查看上传的文件是否为XLS文件?

[英]How to check whether the uploaded file is XLS file or not?

I have a file uploader module. 我有一个文件上传器模块。 The UI is created using simple HTML and Javascript. 用户界面是使用简单的HTML和Javascript创建的。 Server side I am using Java code. 服务器端我正在使用Java代码。 I want to check the type of the uploaded file. 我想检查上传文件的类型。

Files don't really have types. 文件实际上没有类型。 The best you can do would be to attempt to load the file as an XLS. 最好的办法是尝试将文件加载为XLS。

  • If the load succeeds, the file is most likely an XLS. 如果加载成功,则该文件很可能是XLS。
  • If the load fails, the file is either an invalid/malformed XLS, or not an XLS at all. 如果加载失败,则文件要么是无效/格式错误的XLS,要么根本不是XLS。

You can also look at the uploaded file name or the content type, but neither of these is definitive; 您也可以查看上载的文件名或内容类型,但这两个都不是确定的。 ie they might say that the file is an XLS when it is something completely different. 也就是说,当文件完全不同时,他们可能会该文件是XLS。

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

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