Forum Discussion
How to update an Excel sheet in OneDrive from a Python script running locally?
- Dec 21, 2022
You can use the Microsoft Graph API to update an Excel sheet stored in OneDrive from a Python script running locally. Here's an example of how you can do this:
-
First, you will need to register your app in the Azure portal and get the necessary credentials (client ID and client secret) to authenticate your app with the Microsoft Graph API.
-
Next, install the requests and adal libraries in your Python environment:
- Then, use the adal library to obtain an access token for the Microsoft Graph API:
- Now you can use the requests library to make API calls to the Microsoft Graph API. For example, to update a cell in an Excel sheet stored in OneDrive, you can use the PATCH method and pass the access token in the Authorization header:
I hope this helps! Let me know if you have any questions.
(external link removed by moderator) -
You can use the Microsoft Graph API to update an Excel sheet stored in OneDrive from a Python script running locally. Here's an example of how you can do this:
-
First, you will need to register your app in the Azure portal and get the necessary credentials (client ID and client secret) to authenticate your app with the Microsoft Graph API.
-
Next, install the requests and adal libraries in your Python environment:
- Then, use the adal library to obtain an access token for the Microsoft Graph API:
- Now you can use the requests library to make API calls to the Microsoft Graph API. For example, to update a cell in an Excel sheet stored in OneDrive, you can use the PATCH method and pass the access token in the Authorization header:
I hope this helps! Let me know if you have any questions.
- Sophus_SteinDec 23, 2022Copper Contributor
Hi traza8545,
I was able to view all the items present in my ondrive using a Graph API https://graph.microsoft.com/v1.0/me/drive/root/children/sites.
Also found another API to add rows to an excel sheet: https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/workbook/worksheets/Sheet1/tables/{table-id}/rows/add
But it keeps giving me the error mentioned below:
{"error": {"code": "ItemNotFound","message": "The requested resource doesn't exist.","innerError": {"code": "itemNotFound","message": "The requested resource doesn't exist.","date": "2022-12-23T10:34:02","request-id": "73ddfb08-ab4d-4c5b-b094-e199f408c608","client-request-id": "53f7fb58-cf12-7a18-e9c4-88f6ec786849"}}}Will you be able to help me on this?Thanks - Sophus_SteinDec 22, 2022Copper Contributor
Hi traza8545,
Thank you for your reply.
My requirement is to update/write to an already existing excel worksheet. Will you be able to reply with the specific API for this action?
Apologize for the inconvinience but im not able to find an API for update purposes.