Forum Discussion

Sophus_Stein's avatar
Sophus_Stein
Copper Contributor
Dec 21, 2022

How to update an Excel sheet in OneDrive from a Python script running locally?

Hi,

 

I have a python3 script which generates a particular set of data that gets updated to a locally stored Csv/Excel file. I am using Openpyxl package in python to achieve the same.

But the requirement has changed such that the data should be available in a shared platform were multiple personnals can view, edit and export as and when required. This lead to the idea of creating an excel sheet in the microsoft office 365 Excel and updating the sheet so that all the requirements can be met.

Unfortunately, I couldnt find any documentation or tutorial that lets someone update an Excel sheet in office 365 even though i spent a considerable amount of time searching online.

My requirement is to have an API that can take the row in some format and update it to the Excel sheet under my login.

Please help me find a solution to this question or any other alternative that would help to achieve the matter at hand.

 

  • 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:

    1. 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.

    2. Next, install the requests and adal libraries in your Python environment:

    3. Then, use the adal library to obtain an access token for the Microsoft Graph API:
    4. 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)

    Sophus_Stein 

  • traza8545's avatar
    traza8545
    Copper Contributor

    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:

    1. 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.

    2. Next, install the requests and adal libraries in your Python environment:

    3. Then, use the adal library to obtain an access token for the Microsoft Graph API:
    4. 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)

    Sophus_Stein 

Resources