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:
Then tapping Open in app launch the Excel app with 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:
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?
Apparently, the key is rewriting the URL manually, once you know the correct "rules" (this helped). So from this page:
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:
https://name-my.sharepoint.com/personal/full_domain_name
/_layouts/15/Doc.aspx?sourcedoc=%7BCDA3AAB1-D143-4296-949C-D72C2086B8D9%7D&file=
/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)MyFileName.xlsx
ms-excel:ofe|u|
in frontAfter 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!