SheetProtection Class
Worksheet-bound editing protection, using the same locked-cell styles as Excel import/export.
Package: @txtextcontrol/tx-sheet-control. Version: 2.0.0.
ES module import: import { SheetProtection } from '@txtextcontrol/tx-sheet-control';.
Constructor
new SheetProtection(sheet: Worksheet): SheetProtection
| Parameter | Type | Optional | Description |
|---|---|---|---|
sheet | Worksheet | No | Value matching sheet's declared type and the owning object's validation rules. |
Returns: SheetProtection.
Members
Properties
| Property | Description |
|---|---|
| isProtected | The isProtected value of SheetProtection. |
| settings | The settings value of SheetProtection. |
| sheet | The sheet value of SheetProtection. |
Methods
| Method | Description |
|---|---|
| canSelect | Checks protected selection permissions for a rectangle without allocating blank cells. |
| protect | Protects the worksheet. Passwords use Excel's legacy verifier and never enter saved JSON as clear text. |
| unprotect | Removes protection after verifying its password, including modern imported Excel verifiers. |
Examples
Use a fresh workbook. Create and format the sample data, apply this API and retain the returned document or result in your application. In the browser pass editor.workbook; in Node.js pass the server control.
import type { Workbook } from '@txtextcontrol/tx-sheet-control';
function createSheetProtectionReport(book: Workbook) {
const sheet = book.sheets.at(0);
sheet.cell('A1').setText('October invoice');
sheet
.cell('A1')
.format({
fontFamily: 'Liberation Sans',
fontSize: 16,
bold: true,
textColor: '#ffffff',
fillColor: '#163b63',
});
sheet.columns.at(0).setWidth({ pixels: 240 });
sheet.range('B8:B9').setValues([[120], [80]]);
sheet.cell('B10').setFormula('=SUM(B8:B9)');
sheet.range('B8:B10').format({ numberFormatCode: '#,##0.00', fontSize: 11 });
sheet.protection.protect({ password: 'sample-edit-password' });
return sheet;
}