You want to write your own mobile application and need to open Office documents from it ?
Since Microsoft has released Office Mobile on iOS and Android platforms, you probably asked how to open Office documents with these applications from your own application.
After few hours of searches on Google, I didn’t find any information on this subject. So I decided to investigate by myself and I found the solution by using Office Web Apps and by analysing how it works when you click on the option “Edit in Word“.
Office Mobile applications expose some special schemes (like http or https) which allow you to open documents and passing information to the application.
Here is the list of schemes I found through my analysis of Office Web Apps :
- ms-word
- ms-excel
- ms-powerpoint
- onenote
My need is to open in Office Mobile, some documents which are stored in Office 365, but are presented through a dedicated mobile interface (running on iOS). Opening these files with Office Mobile allow users to read and edit them, and save modifications directly to Office 365.
By using previous schemes, it’s easy to build an URL and to open it using the following code :
NSURL *documentURL = [NSURL URLWithString:@"ms-word:https://tenant.sharepoint.com/Shared%20Documents/Document.docx"]; if ([[UIApplication sharedApplication] canOpenURL:documentURL]) { [[UIApplication sharedApplication] openURL:documentURL]; }
As you can see, you just have to concatenate the desired scheme (ms-word: in my case) with the URL of the document.
To ensure that Office Mobile is installed on the device, you can check if the application is able to open it with the call to canOpenURL.
When your application execute the openURL method, the right application is executed and the document is opened. If you’re not authenticated inside the application, you’re invited to do it.
When the document was opened, you probably noticed that it was opened in read-only mode.
It’s the default mode, when you just concatenate an URL to the scheme. But what to do if you want to open the document in edit mode ?
I also found the solution by analysing Office Web Apps 😉
You can specify some additional information between the scheme and the URL of the document.
NSURL *documentURL = [NSURL URLWithString:@"ms-word:ofe%7Cu%7Chttps://tenant.sharepoint.com/Shared%20Documents/Document.docx"]
As you can see above, “ofe%7Cu%7C” was inserted to tell Office Mobile that you want to edit the file (I guess “ofe” means “open for edit”). It’s also possible to use “ofv” (I guess it means “open for view”) in the same manner.
When you run the same code as previously, but with the new URL, the yellow bar below the ribbon has disappeared and you can edit the document without any further action.
Note that after some tests, this also works with Office for Mac (and probably with Office for Windows).
Enjoy 😉
Pingback: Office 365 Developer Podcast: Episode 035 on OneDrive consumer APIs with Ryan Gregg | POKORNY
Pingback: Office 365 Developer Podcast: Episode 035 on OneDrive consumer APIs with Ryan Gregg | Nokipedia
Pingback: Office 365 Developer Podcast: Episode 035 on OneDrive consumer APIs with Ryan Gregg | Office 365 Deployment Autoblog
Pingback: Office 365 Developer Podcast: Episode 035 on OneDrive consumer APIs with Ryan Gregg » PC Portal of Wausau
Pingback: Office 365—monthly Dev Digest for March | POKORNY
Pingback: Office 365—monthly Dev Digest for March | Nokipedia
Pingback: Office 365—monthly Dev Digest for March | Office 365 Deployment Autoblog
Pingback: Office 365—monthly Dev Digest for March » PC Portal of Wausau
I’m trying to open a local file. The path it is not a http:// it is a file:///. There is any way to open it? Or convert the local file path into a http:// path?
LikeLike
Hi Victor,
Due to the security model of iOS applications, it’s not possible to directly open a local file from an application to another application.
If you want to perform this kind of operation, you have to use the UIDocumentInteractionController class available in UIKit.
LikeLike
HI Stéphane Cordonnier!
I have trouble similar.
I can’t open word app with file in local in my app.
If I use UIDocumentInteractionController,I can open word app and can edit my doc file in Word app.
I have question:
1. Could I back to my app with file which I just edit in Word app? How do that?
LikeLike
Hi tranhieutt,
When you open a file with UIDocumentInteractionController, you open a copy of the initial file on the destination application. This copy is stored in the sandbox container of that application.
There’s no way to get back the file inside the original application after the end of editing (because the destination application don’t know who is the source).
LikeLiked by 1 person
Is this method applicable only for files stored on MS Sharepoint? I’m trying to open link to file on normal server (ex. http://jasnet.pl/static/ads/ogloszenia/1a7453de.docx) and i’m getting “wrong link” error.
LikeLike
I didn’t tested with files which are not stored in SharePoint but because I found these capabilities by doing reverse engineering on Office Web Apps (which is component of Office 365), I have some doubts that it can work with files stored on a “normal server”.
LikeLike
Hi Michael,
I am also facing some issues while opening excel file in office 365
My Code:
NSString *path=@”https://www.google.ch/url?sa=t&rct=j&q=&esrc=s&source=web&cd=8&cad=rja&uact=8&ved=0CE8QFjAHahUKEwinwLekqPvHAhVILhoKHetDDRQ&url=http%3A%2F%2Fopendatakit.org%2Fwp-content%2Fuploads%2Fstatic%2Fsample.xls&usg=AFQjCNFYlLuJBYfQ8EawVQx2MFmKqL3UXw&bvm=bv.102829193,d.bGg”;
NSURL *documentURL = [NSURL URLWithString:[[NSString stringWithFormat:@”ms-excel:ofv|u|%@”,path] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL:documentURL]) {
[[UIApplication sharedApplication] openURL:documentURL];
}
Issue:Excel can’t open this workbook.
Please help me out to open, edit excel in office 365 from my app.
LikeLike
Pingback: Office 365—monthly Dev Digest for March |
Pingback: Office 365—monthly Dev Digest for March – Office.com/setup Blog | www.office.com/setup
what is the protocol for Acrobat reader, as for microsoft word it is ms-word
LikeLike
Can I open the particular page, by sending the page number in the url link.
LikeLike
Can I open the particular page of a word document, by sending the page number in the url link.
LikeLike