简体   繁体   中英

Open URL to excel file in Android MS Excel from my app

I'm trying to open file URL in MS Excel on Android.

Here is my code:

     webDavUrl = URLEncoder.encode("ms-excel:ofv|u|", "utf-8") + webDavUrl + URLEncoder.encode("?dl=0|p|xxxxxx|z|yes|a|App", "utf-8");
    Uri uri =  Uri.parse(webDavUrl);
    PackageManager manager = getContext().getPackageManager();
    Intent intent = manager.getLaunchIntentForPackage("com.microsoft.office.excel");
    if (intent != null) {
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setDataAndType(uri, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    }
    startActivity(intent);

I followed this document . But I can't find out how to pass URL to MS Excel. Can somebody help me with this?

This code works for me:

String davUrl = "ms-excel:ofv|u|" + urlToFile;

Uri uri =  Uri.parse(davUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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