Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type
Least privileged permissions
Higher privileged permissions
Delegated (work or school account)
Files.ReadWrite
Not available.
Delegated (personal Microsoft account)
Files.ReadWrite
Not available.
Application
Not supported.
Not supported.
HTTP request
POST /me/drive/items/{id}/workbook/worksheets/{id|name}/protection/protect
POST /me/drive/root:/{item-path}:/workbook/worksheets/{id|name}/protection/protect
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Drives.Item.Items.Item.Workbook.Worksheets.Item.Protection.Protect;
using Microsoft.Graph.Models;
var requestBody = new ProtectPostRequestBody
{
Options = new WorkbookWorksheetProtectionOptions
{
AllowFormatCells = true,
AllowFormatColumns = true,
AllowFormatRows = true,
AllowInsertColumns = true,
AllowInsertRows = true,
AllowInsertHyperlinks = true,
AllowDeleteColumns = true,
AllowDeleteRows = true,
AllowSort = true,
AllowAutoFilter = true,
AllowPivotTables = true,
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Workbook.Worksheets["{workbookWorksheet-id}"].Protection.Protect.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.drives.item.items.item.workbook.worksheets.item.protection.protect.ProtectPostRequestBody protectPostRequestBody = new com.microsoft.graph.drives.item.items.item.workbook.worksheets.item.protection.protect.ProtectPostRequestBody();
WorkbookWorksheetProtectionOptions options = new WorkbookWorksheetProtectionOptions();
options.setAllowFormatCells(true);
options.setAllowFormatColumns(true);
options.setAllowFormatRows(true);
options.setAllowInsertColumns(true);
options.setAllowInsertRows(true);
options.setAllowInsertHyperlinks(true);
options.setAllowDeleteColumns(true);
options.setAllowDeleteRows(true);
options.setAllowSort(true);
options.setAllowAutoFilter(true);
options.setAllowPivotTables(true);
protectPostRequestBody.setOptions(options);
graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").workbook().worksheets().byWorkbookWorksheetId("{workbookWorksheet-id}").protection().protect().post(protectPostRequestBody);