【问题标题】:Intent to read both .xls and xlsx files in Android?打算在 Android 中同时读取 .xls 和 xlsx 文件?
【发布时间】:2020-12-08 10:45:16
【问题描述】:

我的意图选择.xls 而

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

同时选择.xlsx

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

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

【问题讨论】:

标签: android android-intent xlsx xls


【解决方案1】:

对于.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);

对于其他扩展:

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

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

【讨论】:

    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    相关资源
    最近更新 更多