打算读取 Android 中的 .xls 和 xlsx 文件?

Intent to read both .xls and xlsx files in Android?

我的意图选择 .xls

fileintent.setType("application/vnd.ms-excel");

选择 .xlsx

fileintent.setType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

如何使 .xls.xlsx 都可以选择和阅读?感谢帮助!

对于 .xls.xlsx 扩展,

Mimetypes 是俱乐部。

Intent intent;
    
        String[] mimetypes =
                { "application/vnd.ms-excel", // .xls
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" // .xlsx
                       };

        intent = new Intent(Intent.ACTION_GET_CONTENT); // or use ACTION_OPEN_DOCUMENT
        intent.setType("*/*");
        intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
        intent.addCategory(Intent.CATEGORY_OPENABLE);

对于其他分机:

检查以下link,找到对应的mimetype并包含在上面的代码中。

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types