TX Sheet Control

Protection Class

Class
Namespace
TXTextControl.TXSheetControl.Server
Package
TXTextControl.TXSheetControl.Server from the private NuGet feed or the supplied NuGet folder
Assembly
TXTextControl.TXSheetControl.Api.dll
Install
dotnet add package TXTextControl.TXSheetControl.Server .NET 10 and later.
Also in
TXTextControl.TXSheetControl.Blazor as TXTextControl.TXSheetControl.Api.dll
Inherits
  1. DocumentObject
  2. Protection

Enforced worksheet editing permissions using the same locked-cell styles as the JavaScript editor.

Syntax

public class Protection

Members

Methods

MethodDescription
CanSelectAsyncChecks whether protected-sheet permissions permit selecting a rectangle.
GetSettingsAsyncReads detached protection metadata without exposing a clear-text password.
ProtectAsyncEnables protection with explicitly granted editing permissions.
UnprotectAsyncVerifies the password before removing protection; use outside a synchronous workbook batch.

Examples

Build a small report using this document API and return its PDF bytes. Pass a live control with a fresh workbook; the caller owns its lifetime.

using TXTextControl.TXSheetControl.Server;

async Task<byte[]> CreateProtectionReportAsync(ServerSheetControl control)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    await sheet.Cell("B8").SetValueAsync(120);
    await sheet.Cell("B9").SetValueAsync(80);
    await sheet.Cell("B10").SetFormulaAsync("=SUM(B8:B9)");

    var protection = sheet.Protection;
    await protection.ProtectAsync(new ProtectionOptions { Password = "sample-edit-password" });
    return await control.SaveAsync(StreamType.PDF);
}

See Also