Search code examples
androidexcelandroid-intentsharepointandroid-deep-link

Open a Sharepoint online Excel file in the Excel app for Android using a link or intent


I would like to launch the Excel for Android app with an online file (from Sharepoint) opened for editing, exactly like the app does when creating a widget with a link (file > overflow menu > Add to Home screen).

The problem is that I cannot use the widget itself, because I need the linked file to change every day. So I'm using Graph API to retrieve the URI to the Excel file which is something like this:

https://name-my.sharepoint.com/personal/full_domain_name/_layouts/15/Doc.aspx?sourcedoc=%7BCDA3AAB1-D143-4296-949C-D72C2086B8D9%7D&file=MyFileName.xlsx&action=default&mobileredirect=true

If I navigate to that URL with a browser when logged in, I can see the file contents:

Excel Sharepoint file in browser with Open in app command

Then tapping Open in app launch the Excel app with the file.

Excel Android app opens the Sharepoint link to the file

I would like to automate this using either an Intent or a specially built URI that can invoke the Excel app directly, like the widget or the Open in app function do. However, I cannot find any documentation, maybe it is not possible?

Microsoft says there are specific URIs to do that, but if I try with:

ms-excel:ofe|u|https://name-my.sharepoint.com/personal/full_domain_name/_layouts/15/Doc.aspx?sourcedoc=%7BCDA3AAB1-D143-4296-949C-D72C2086B8D9%7D&file=MyFileName.xlsx|a|App

I always get an error message:

Excel App opening a ms-excel:ofe|u| URI results in an error

I also tried getting the download URI from the Graph API @microsoft.graph.downloadUrl attribute, which results in an URI like this:

https://name-my.sharepoint.com/personal/full_domain_name/_layouts/15/download.aspx?UniqueId=cda3aab1-d143-4296-949c-d72c2086b8d9&Translate=false&tempauth=eyJhbALOTOFCHARACTERS&ApiVersion=2.0

However, launching that in a browser (or sending an android.intent.action.VIEW intent, which opens the browser too) results in a file download dialog. I would like to open the online file directly and this is possible with the widget, so there should be a way?


Solution

  • Apparently, the key is rewriting the URL manually, once you know the correct "rules" (this helped). So from this page:

    Excel Sharepoint file in browser with Open in app command

    you first have to copy the URL visible in the browser, for example like so:

    https://name-my.sharepoint.com/personal/full_domain_name/_layouts/15/Doc.aspx?sourcedoc=%7BCDA3AAB1-D143-4296-949C-D72C2086B8D9%7D&file=MyFileName.xlsx&action=default&mobileredirect=true

    Then, from that URL:

    1. keep the part: https://name-my.sharepoint.com/personal/full_domain_name
    2. remove the part: /_layouts/15/Doc.aspx?sourcedoc=%7BCDA3AAB1-D143-4296-949C-D72C2086B8D9%7D&file=
    3. add the path of where the file is located (important!) according to the OneDrive for Business folders, for example: /Documents/Folder%20with%spaces/ (💡 tip: make sure to insert /Documents/ because it seems necessary for OneDrive for Business links, even though it's not visible in the browser folder tree)
    4. keep the file name: MyFileName.xlsx
    5. remove the rest
    6. add ms-excel:ofe|u| in front

    After applying the edits, the URL above becomes:

    ms-excel:ofe|u|https://name-my.sharepoint.com/personal/full_domain_name/Documents/Folder%20with%spaces/MyFileName.xlsx

    Navigating to that URL from a link (or sending an Intent) should open that file directly in Excel!

    Excel Android app opens the Sharepoint link to the file