Category Archives: Office Mobile

Opening a document with Office Mobile from your own application

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.

Office Mobile - View Mode

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.

Office Mobile - Edit mode

Note that after some tests, this also works with Office for Mac (and probably with Office for Windows).

Enjoy  😉