How to get a preview for an excel file stored in onedrive with an exact sheet from the workbook chosen ?

Vikas Krishnan 1 Reputation point
2021-08-31T09:39:49.25+00:00

I need to preview a user uploaded excel file in my web application. From the Micorsoft Graph API to interact with Onedrive I could understand that I can get iFrame embed links either using createlink api or preview api.

Here I have an additional requirement to choose a particular sheet from the available multiple sheets in the work book when the preview is shown itself.

I have seen that the preview api has a parameter "page" to pass in body but could not see a positive change thought I had passed the probable inputs.

  1. For example I have a workbook sample.xlsx in onedrive.
  2. and workbook have sheet1 sheet2 and sheet3 as worksheets
  3. I am getting a preview embed link via preview api and embed it in an iframe.
  4. But this will show sheet3 as chosen by default. where I need to show sheet2.

Is there somehow I could acheive this via graph api ?

So can anyone help me in this with, is there a way to preview an excel file stored in one drive with a particular sheet selected or can we pass it in the api body?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,674 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JosephXu-MSFT 531 Reputation points
    2021-09-01T07:13:47.537+00:00

    Hi@Vikas Krishnan Per my test, we can use Worksheet: Range to preview specified worksheet.

    1. Following is my excel file in my onedrive.
      128213-image.png
    2. We can find its item id via https://graph.microsoft.com/v1.0/me/drive/root/children.
      128128-image.png
    3. We can specify the sheet name and range in this api https://graph.microsoft.com/v1.0/me/drive/items/{item-id}/workbook/worksheets('{sheet-name}')/range(address='A2:F11')?$select=values. We can see the values in my worksheet.
      128192-image.png