In the .net Graph SDK, Range().Clear() gives compilation error and doesn't work as told in documentation

131 Views Asked by At

I am using .net Graph SDK (Microsoft.Graph) version 3.21. I am following the below documentation link from Microsoft: https://learn.microsoft.com/en-us/graph/api/range-clear?view=graph-rest-1.0&tabs=csharp In this link, it is said that we can clear a range of cells and C# code to do so is given. When I try, I am getting error for the Clear I am able to get Range, but the clear shows error. Error CS1061 'IWorkbookWorksheetRangeRequestBuilder' does not contain a definition for 'Clear' and no accessible extension method 'Clear' accepting a first argument of type 'IWorkbookWorksheetRangeRequestBuilder' could be found (are you missing a using directive or an assembly reference?)

Am I missing something? What else am I supposed to do?

Note: All other Graph calls work. I am able to retrieve Range: var range = await _graphServiceClient.Sites["root"].Drives[file.ParentReference.DriveId] .Items[file.Id].Workbook.Worksheets["Sheet1"].Range().Request().GetAsync();

1

There are 1 best solutions below

0
On

It seems a bug, not only Clear but also Delete/Format/Merge... are not contained. There is a similar issue. The methods work in Java but not C#, Filipowicz251 has commented it in Github.

You could call HTTP Request to clear range values without sdk.

POST https://graph.microsoft.com/v1.0/me/drive/items/{id}/workbook/names/{name}/range/clear
Content-type: application/json
Content-length: 32

{
  "applyTo": "applyTo-value"
}

Example here: https://vincentlauzon.com/2017/01/31/using-microsoft-graph-api-to-interact-with-azure-ad/