XLSX

Protection

Lock worksheets and workbooks, define protected ranges, and share files with passwords

Sheet Protection

Protect a worksheet with a password and restrict user actions. When a plaintext password is provided, the legacy XOR hash and modern SHA-512 hash are both computed automatically.

{
  "worksheets": [
    {
      "name": "Protected",
      "rows": [
        { "cells": [{ "value": "Quarter" }, { "value": "2023" }, { "value": "2024" }] },
        { "cells": [{ "value": "Q1" }, { "value": 100 }, { "value": 120 }] },
        { "cells": [{ "value": "Q2" }, { "value": 150 }, { "value": 170 }] }
      ],
      "protection": {
        "sheet": true,
        "password": "secret",
        "formatCells": false,
        "insertRows": false,
        "sort": false
      }
    }
  ]
}

Sheet Protection Options

OptionTypeDescription
sheetbooleanEnable sheet protection
passwordstringPlaintext password (auto-hashed)
objectsbooleanProtect objects
scenariosbooleanProtect scenarios
formatCellsbooleanAllow formatting cells
formatColumnsbooleanAllow formatting columns
formatRowsbooleanAllow formatting rows
insertColumnsbooleanAllow inserting columns
insertRowsbooleanAllow inserting rows
insertHyperlinksbooleanAllow inserting hyperlinks
deleteColumnsbooleanAllow deleting columns
deleteRowsbooleanAllow deleting rows
selectLockedCellsbooleanAllow selecting locked cells
sortbooleanAllow sorting
autoFilterbooleanAllow auto filter
pivotTablesbooleanAllow pivot tables
selectUnlockedCellsbooleanAllow selecting unlocked cells

Modern Encryption

When password is provided, both a legacy XOR hash (for compatibility) and a modern SHA-512 hash with random salt and 100,000 iterations are generated automatically. You can also provide pre-computed values directly:

{
  "protection": {
    "sheet": true,
    "algorithmName": "SHA-512",
    "hashValue": "base64hash...",
    "saltValue": "base64salt...",
    "spinCount": 100000
  }
}
OptionTypeDescription
algorithmNamestringHash algorithm (e.g. "SHA-512")
hashValuestringBase64-encoded password hash
saltValuestringBase64-encoded salt
spinCountnumberNumber of hash iterations

Protected Ranges

Define named ranges within a protected sheet that specific users can edit:

{
  "worksheets": [
    {
      "name": "Protected",
      "rows": [
        { "cells": [{ "value": "Quarter" }, { "value": "2023" }, { "value": "2024" }] },
        { "cells": [{ "value": "Q1" }, { "value": 100 }, { "value": 120 }] },
        { "cells": [{ "value": "Q2" }, { "value": 150 }, { "value": 170 }] }
      ],
      "protection": {
        "sheet": true,
        "password": "secret"
      },
      "protectedRanges": [{ "name": "EditableRange", "sqref": "B2:C5", "password": "range1" }]
    }
  ]
}

Protected Range Options

OptionTypeDescription
namestringRange name (required)
sqrefstringCell range reference, e.g. "B2:C5" (required)
passwordstringPlaintext password (auto-hashed)
algorithmNamestringHash algorithm for modern encryption
hashValuestringBase64-encoded password hash
saltValuestringBase64-encoded salt
spinCountnumberNumber of hash iterations
securityDescriptorstringSID security descriptor string

Workbook Protection

Lock workbook structure and windows at the workbook level. Supports separate passwords for structure and revisions:

{
  "workbookProtection": {
    "lockStructure": true,
    "lockWindows": true,
    "workbookPassword": "admin"
  },
  "worksheets": [
    {
      "name": "Data",
      "rows": [{ "cells": [{ "value": "Protected workbook" }] }]
    }
  ]
}

Workbook Protection Options

OptionTypeDescription
lockStructurebooleanLock workbook structure (add/delete/rename sheets)
lockWindowsbooleanLock workbook windows
lockRevisionbooleanLock revisions
workbookPasswordstringPlaintext structure password (auto-hashed)
revisionsPasswordstringPlaintext revisions password (auto-hashed)

Both passwords also support modern encryption options: workbookAlgorithmName, workbookHashValue, workbookSaltValue, workbookSpinCount and revisionsAlgorithmName, revisionsHashValue, revisionsSaltValue, revisionsSpinCount.

File Sharing

Recommend read-only mode and record who has the file open:

{
  "fileSharing": {
    "readOnlyRecommended": true,
    "userName": "John"
  },
  "worksheets": [
    {
      "name": "Data",
      "rows": [{ "cells": [{ "value": "Shared file" }] }]
    }
  ]
}

File Sharing Options

OptionTypeDescription
readOnlyRecommendedbooleanRecommend read-only mode
userNamestringUser name who has the file locked
reservationPasswordstringPlaintext reservation password (auto-hashed)
algorithmNamestringHash algorithm for modern encryption
hashValuestringBase64-encoded password hash
saltValuestringBase64-encoded salt
spinCountnumberNumber of hash iterations
Copyright © 2026