Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How to Password-Protect an Excel Workbook and Individual Worksheets via API

Description and use

A single API call can simultaneously apply three Excel protection layers—file encryption, workbook structure protection, and worksheet content protection—preventing unauthorized access and edits.

Problem

Finance teams often send pricing workbooks that get unintentionally altered because the files lack proper protection, leading to incorrect totals.

Outcome

A single API call can apply all three Excel protection layers, preventing unauthorized opening, sheet manipulation, and cell editing. The fallback behavior of the primary password ensures consistent protection unless explicitly overridden.

Workflow

  • 1. Prepare the Excel file to be protected.
  • 2. Construct a POST request to https://api.pdf4me.com/office/ApiV2Excel/ExcelSecure with JSON body containing the document name, optional docContent, and a secureExcelAction object specifying passwords and protection flags.
  • 3. Set the "password" field to encrypt the file and optionally use it as a fallback for other protections.
  • 4. Enable "protectWorkbook" and provide "protectWorkbookPassword" to lock the workbook structure.
  • 5. Enable "protectWorksheets" and provide "worksheetProtectionPassword" and "worksheetProtectionType" to lock cell-level editing.
  • 6. Specify "worksheetNames" or "worksheetIndexes" to target specific sheets; leave empty to protect all sheets.
  • 7. Send the request with proper Authorization header. 8. Receive the response containing the Base64-encoded protected file, filename, success flag, and any error message.
  • 9. Distribute the protected file to reviewers, providing the necessary passwords for opening and editing as required.

Evidence

Excel actually gives you three separate locks for exactly this problem, and most developers only ever reach for one of them, if any.

Source

PDF4me's Office API exposes all three through a single call: Secure Document for Excel.

Source

If you set password but leave protectWorkbookPassword and worksheetProtectionPassword empty, PDF4me doesn't leave those two layers unprotected. It uses password for them too.

Source

Set all three passwords independently and you can hand one reviewer the file-open password and a completely different, separate password for editing the protected sheets.

Source

  • Record date: 2026-10-10T17:56:23.476Z