Skip to content

[BUG] Worksheet protection with sort: true and autoFilter: true doesn't allow sorting in Excel #2992

@sjadiscohen

Description

@sjadiscohen

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions