Search code examples
excelmicrosoft-graph-apisharepoint-onlineonedrive

Microsoft Graph API: how to use the "clear" endpoint and keep columns number format on excel file?


My application uses Microsoft Graph API for inserting data on Excel Files. Before inserting the new data, we need to clear the previous one. The problem is that everytime we call the clear endpoint, all the number formating like currency, date, etc., is lost.


Solution

  • The clear endpoint

    POST /me/drive/items/{id}/workbook/names/{name}/range/clear
    

    has optional parameter applyTo in request body which determines the type of clear action. The possible values are: All, Formats, Contents.

    If you set Contents it should clear only values in cells and preserves formatting etc.

    {
      "applyTo": "Contents"
    }
    

    Resource:

    range clear