Search code examples
excelgoogle-sheetsmicrosoft-graph-api

Is it possible to bulk replace strings in an Excel file via API?


Is it possible to bulk replace strings in an Excel file via API?

Hello, I am aware that Google Sheets has an API called "FindReplaceRequest" (https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#findreplacerequest)
which can be used to replace values in a spreadsheet with any desired string.

I am interested in achieving the same functionality in Microsoft Excel. I have come across the Microsoft Graph API (https://learn.microsoft.com/en-us/graph/overview)
but I am not sure if this API can be used or if there are other methods available to achieve this.

Could you please advise if it is possible to replace strings in an Excel file via Microsoft Graph API?
If not, how can I do that with any other methods?

I would greatly appreciate any insights as I am not very familiar with Microsoft services, thank you in advance.


Solution

  • You can use Microsoft Graph to invoke any workbook function.

    Check list of supported functions.

    Example for replace function

    POST https://graph.microsoft.com/beta/me/drive/root:/path/to/file/fileName.xlsx:/workbook/functions/replace
    content-type: Application/Json 
    authorization: Bearer {access-token} 
    workbook-session-id: {session-id}
    
    {
        "oldText": "old text",
        "startNum": 0,
        "numChars": 8,
        "newText": "new text"
    }