2
votes

I'm trying to create a new excel file in OneDrive with the below properties of the REST API call.

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

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

Header: Content-Type:application/json

With the help of the above properties, I'm able to create the file in OneDrive. But it is created without size & If I try to open the workbook it says Couldn't Open the Workbook Error The workbook cannot be opened.

Basically, whenever I create a new excel file from UI it has a default size of 7.81KB (Could be used for metadata of file).

I have taken reference from https://docs.microsoft.com/en-us/graph/api/driveitem-post-children?view=graph-rest-1.0&tabs=http

Is there anyone who knows how to resolve this issue?

1

1 Answers

0
votes

Graph API doesn't not support creating an empty excel file. Only way is to either upload an empty excel file from your local storage or copy a empty excel file created in OneDrive.

I'm using the second way. I have a empty template for excel file in OneDrive and create a new excel file from this template by calling the endpoint

POST  https://graph.microsoft.com/v1.0/me/drive/items/{template_item-id}/copy

Copy item