Is there any MS Graph API to create workbook in given path?

ffbld01@uk.ibm.com 96 Reputation points
2022-04-28T13:31:56.073+00:00

We tried creating an Excel file using the following API, and payload. But it generates the corrupted excel file with 0 size.

https://graph.microsoft.com/v1.0/me/drive/root/children

{
  "name": "test2.xlsx",
  "file":{ }
}

Request your help to get the right payload or API to create empty excel file in given onedrive path

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

Accepted answer
  1. JanardhanaVedham-MSFT 3,566 Reputation points
    2022-04-28T17:01:16.353+00:00

    Hi @ffbld01@uk.ibm.com ,

    As mentioned in this documentation , currently Microsoft Graph Excel REST API only supports or allows to read and modify Excel workbooks (or Excel files) stored in OneDrive for Business, SharePoint site or Group drive.

    197454-image.png

    You can also go through this relevent question and answer in stack overflow as well.

    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. John Wellesz 5 Reputation points
    2023-10-30T19:04:31.3466667+00:00

    This is not true anymore: although the created file has a 0 size after creation it can be used within Microsoft Excel online and other Microsoft graph APIs.

    Making a POST request on https://graph.microsoft.com/v1.0/me/drive/root/children) with the payload below creates a file with the correct mime type (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)

    {"file":{},"name":"testAPISDK.xlsx","@microsoft.graph.conflictBehavior":"rename"}
    

    Then you can make further queries on the created file, like getting worksheets and writing values to it (it will correctly return that there is one worksheet named 'Sheet1' despite the size being 0...)

    1 person found this answer 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.