In this article I will demonstrate how to get sample information from an Excel file stored in a OneDrive, using nothing more than the Microsoft Graph API.
Introduction
Richard diZerega blogged about and has talked further on the new beta graph API capability for Using OneDrive and Excel APIs in the Microsoft Graph for App Storage. Using that as a reference and the Excel REST API for the graph documentation I was able to piece together this example.
Getting data from an excel file
Load a sample excel file into your OneDrive root, in this case marky.xlsx with a simple example
Access the file using the Graph API
Using the Graph Explorer we are able to test out our files. Note that this is currently (1 Aug 2016) in BETA and the left hand drop down for version must be beta. The URLs referenced in this article all contain /beta/. Once the capability goes GA then it will become part of the next version 1.0+.
- Getting the file
- Access the one drive root
- https://graph.microsoft.com/beta/me/drive/root/children
- Getting into the workbook
- Get the id of the file “01OCINHMQ34P4YPTLFDBE3ETCRZ7ATG5KG” in this case
- https://graph.microsoft.com/beta/me/drive/items/01OCINHMQ34P4YPTLFDBE3ETCRZ7ATG5KG/workbook/worksheets
- Get the Range of cells to be seen (A1:C4)
- get the id of the workbook “{00000000-0001-0000-0000-000000000000}” in this case
- https://graph.microsoft.com/beta/me/drive/items/01OCINHMQ34P4YPTLFDBE3ETCRZ7ATG5KG/workbook/worksheets(‘{00000000-0001-0000-0000-000000000000}’)/Range(address=’Sheet1!A1:C4′)
and there we have our data from the excel file – pretty simple eh !
Conclusion
Using the Microsoft Graph API we can easily reach into an excel file, stored in OneDrive and extract the data for use in other places.
EDIT
And then not two days later this went GA – so v1.0 also now works 🙂