How do I modify an Excel file in my personal onedrive through python

Jason Magoto 0 Reputation points
2025-10-20T02:39:07.92+00:00

My apologies if this is in the wrong location, I don't really understand Azure's services and I'm not sure where best to put this.

I'm trying to write a small python script that can edit an Excel file on my personal OneDrive. This is for a small personal project, not related to a company or a tenant or anything. I simply have a personal microsoft account, where I have saved an excel file and I would like to be able to edit it programmatically.

Google sheets has an api where I was able to do something similar rather easily, and I would like to achieve something similar with Excel because I would like to migrate my workflow to excel rather than sheets. But I just can't wrap my head around how this all works. I've read that I need to register an app and get a token and whatnot. But I don't have a developer account, I don't have a tenant. I'm just a personal account with an excel file. Am I thinking about this wrong or is there just not really an easy solution for this type of use case? Thanks in advance!


Moved from: Community Center | Not monitored

Microsoft 365 and Office | Excel | Other | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tasadduq Burney 9,051 Reputation points MVP Volunteer Moderator
    2025-11-18T19:48:45.07+00:00

    To modify an Excel file in your personal OneDrive using Python, you can use the Microsoft Graph API. Here are the basic steps:

    1. Register an App: Go to the Azure App Registration Portal and register a new application. Note the Application (client) ID and the Directory (tenant) ID.
    2. Set Permissions: In the app registration, go to API permissions and add the following delegated permissions for Microsoft Graph: Files.ReadWrite.
    3. Authentication: Use the msal library to handle authentication and get an access token. Install it using pip install msal.
    4. Modify the Excel File: Use the requests library to interact with the Microsoft Graph API and modify the Excel file.

    Here is a sample Python script to get you started:

    import msal  
    import requests
    
    # Define the necessary variables  
    client_id = 'YOUR_CLIENT_ID'  
    client_secret = 'YOUR_CLIENT_SECRET'  
    tenant_id = 'YOUR_TENANT_ID'  
    authority = f'https://login.microsoftonline.com/{tenant_id}'  
    scope = ['https://graph.microsoft.com/.default
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.