Reputation: 163
I'm trying to create an empty Excel workbook in OneDrive using the Microsoft Graph API. I've tried a variety of requests but OneDrive does not pick up that it is Excel just based on the extension. The only examples I've found are C# SDK examples and I'm looking to do this in another language without an SDK
The following creates the file but creates it with a mime-type of application/octet-stream
PUT /v1.0/me/drive/items/root:/NewWorkbook.xlxs:/content HTTP/1.1
Host: graph.microsoft.com
Content-Type: application/json
Authorization: Bearer <REDACTED>
{
"name": "NewWorkbook.xlxs",
"file": {
}
}
I found a similar ask from a few years ago but Microsoft Graph has undergone a lot of changes since then so I would assume the answers to be somewhat dated https://stackoverflow.com/a/38901596/10255083
Upvotes: 1
Views: 1289
Reputation: 46
Currently, there is no Microsoft Graph API to create an empty Excel workbook in OneDrive. Besides using the API of Upload a DriveItem as you mentioned, another option is to use the API of Copy a DriveItem, which, however, requires to have an Excel workbook file in OneDrive before the operation.
Upvotes: 1
Reputation: 2236
There is an office JS API called createWorkbook API, it can create an workbook, but it seems this API not yet expose to Excel Graph, therefore graph doesn't support create an empty workbook.
if you have an excel add-in you can use this API to create a workbook, or if you don't want to open the workbook, then maybe you could use a workaround to duplicate a pre-saved empty workbook and then use Graph API to update the duplicated workbook.
Upvotes: 0