excel_protect_worksheet
Secure Excel worksheets with password protection to control user permissions for editing, formatting, and cell selection in financial spreadsheets.
Instructions
Protect a worksheet with a password
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| allowFormatCells | No | ||
| allowFormatColumns | No | ||
| allowFormatRows | No | ||
| allowSelectLockedCells | No | ||
| allowSelectUnlockedCells | No | ||
| password | Yes | ||
| worksheetName | Yes |
Implementation Reference
- src/tools/excel-tools.ts:334-355 (handler)Main tool handler that constructs protection options and calls ExcelManager.protectWorksheethandler: async (args: any): Promise<ToolResult> => { try { const protection = { selectLockedCells: args.allowSelectLockedCells, selectUnlockedCells: args.allowSelectUnlockedCells, formatCells: args.allowFormatCells, formatColumns: args.allowFormatColumns, formatRows: args.allowFormatRows }; await excelManager.protectWorksheet(args.worksheetName, args.password, protection); return { success: true, message: `Protected worksheet: ${args.worksheetName}` }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error) }; } }
- src/tools/excel-tools.ts:321-333 (schema)Input schema defining parameters for protecting a worksheet including permissionsinputSchema: { type: "object", properties: { worksheetName: { type: "string" }, password: { type: "string" }, allowSelectLockedCells: { type: "boolean", default: true }, allowSelectUnlockedCells: { type: "boolean", default: true }, allowFormatCells: { type: "boolean", default: false }, allowFormatColumns: { type: "boolean", default: false }, allowFormatRows: { type: "boolean", default: false } }, required: ["worksheetName", "password"] },
- src/excel/excel-manager.ts:224-239 (helper)Core helper method that applies protection to the worksheet using ExcelJSasync protectWorksheet( worksheetName: string, password: string, options?: Partial<ExcelJS.WorksheetProtection> ): Promise<void> { if (!this.workbook) { throw new Error('No workbook is currently open'); } const worksheet = this.workbook.getWorksheet(worksheetName); if (!worksheet) { throw new Error(`Worksheet "${worksheetName}" not found`); } await worksheet.protect(password, options || {}); }
- src/index.ts:32-44 (registration)Registration of all tools including excelTools which contains excel_protect_worksheetconst allTools = [ ...excelTools, ...financialTools, ...rentalTools, ...expenseTools, ...reportingTools, ...cashFlowTools, ...taxTools, ...analyticsTools, ...chartTools, ...complianceTools, ...propertyTools, ];