Microsoft Graph API - Access Excel content

SJ 21 Reputation points
2022-06-29T09:10:13.763+00:00

Hello everyone,

I am a beginner learning to use API, and I would like some help accessing the content of an Excel file stocked within a OneDrive.

I managed to access a specific cell's content using this query :
https://graph.microsoft.com/v1.0/me/drive/items/{item-id}/workbook/worksheets/{worksheet-id}/cell(row=3,column=2)

But I am struggling to find information about the following queries :

  • obtaining the content of the cells of a specific column
  • find a specific value within a column (let's say C1), identifying its row (for instance R12), and then getting the content of a cell from that row and another specific column (R12-C3 for instance)

I would be thankful if anyone could give me any pointers/tips or documentation on how to achieve that.

Thank you for your time.

Microsoft 365 and Office SharePoint Development
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Shivam Dhiman 6,081 Reputation points
    2022-06-29T12:00:40.39+00:00

    Hi @SJ

    Please follow the below steps-

    Step1: Get the range of used values of your sheet using this https://graph.microsoft.com/v1.0/me/drives/{drive-id}/items/{item-id}/workbook/worksheets/{sheet-id}/usedRange Graph API reference. In response you will find "address": "Sheet1!A1:F14" property which indicates smallest range that encompasses any cells that have a value or formatting assigned to them. Use this to find last value of your column and put that in address in next step.

    Step2: To get values from worksheet of particular column use
    GET https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/worksheets/{sheet-id}/range(address='A1:A14')?$select=values Graph API. Please refer to this documentation for more details.

    216089-address.png

    If you want to get contents of column in excel for particular table you can use this GET https://graph.microsoft.com/v1.0/me/drives/{drive-id}/items/{item-id}/workbook/worksheets/{sheet-id}/tables/{table-id}/columns/{column-id} Graph API for more details please refer to this documentation.

    In a response you will get all the content of column use that(or usedRange) to identify row number, after that you can use this
    GET https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/worksheets/{sheet-id}/range(address='A7:F7') Graph API to get the result.

    216144-address3.png

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.