-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
Bug Description
When using worksheet protection with sort: true and autoFilter: true options, the generated Excel file still prevents sorting and shows the error: "The cell or chart you're trying to change is on a protected sheet. To make a change, unprotect the sheet."
Expected Behavior
Based on Excel's documentation and protection options, setting sort: true and autoFilter: true should allow users to sort and filter data while keeping specific cells locked.
Actual Behavior
Excel blocks all sorting operations on the protected sheet, even with explicit sort permissions enabled.
Code to Reproduce
const workbook = new ExcelJS.Workbook()
const worksheet = workbook.addWorksheet('Test')
// Add sample data
worksheet.columns = [
{ header: 'ID', key: 'id', width: 10 },
{ header: 'Name', key: 'name', width: 20 },
{ header: 'Department', key: 'department', width: 20 }
]
worksheet.addRows([
{ id: 1, name: 'John', department: 'IT' },
{ id: 2, name: 'Jane', department: 'HR' }
])
// Lock some cells
worksheet.getCell('A2').protection = { locked: true }
worksheet.getCell('A3').protection = { locked: true }
// Enable autofilter
worksheet.autoFilter = { from: 'A1', to: 'C3' }
// Protect with sort and autoFilter permissions
await worksheet.protect('password', {
selectLockedCells: true,
selectUnlockedCells: true,
sort: true, // Should allow sorting
autoFilter: true, // Should allow filtering
formatCells: false,
insertRows: false,
deleteRows: false
})Metadata
Metadata
Assignees
Labels
No labels