问题
My intent picks .xls
while
fileintent.setType("application/vnd.ms-excel");
Picks .xlsx
while
fileintent.setType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
How to make both .xls
and .xlsx
selectable and readable? Appreciate help!
回答1:
For .xls
and .xlsx
extensions,
Mimetypes are clubbed.
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);
For other extensions:
Check the following link, find the corresponding mimetype and include it in the above code.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
来源:https://stackoverflow.com/questions/63482335/intent-to-read-both-xls-and-xlsx-files-in-android