How to set a password on an XLSX file

Sheetise XLSX Password Setter for .NET provides a simple yet powerful API for applying password protection to an Excel workbook while preserving all worksheets, charts and formatting. This is useful when you need to secure a file before sharing it or integrating it into pipelines that require encrypted Excel files.

Main Features

Apply a Password to an XLSX

Encrypt an existing XLSX file with a user‑defined password. The protection covers opening the file, and optional restrictions on editing, printing and structure.

Preserve Formatting & Objects

All cell styles, formulas, tables, charts and images remain intact after encryption.

Streaming Support

Protect large workbooks in a streaming fashion to keep memory usage low, ideal for batch processing of many files.

Detailed Instructions

XLSX Password‑Protection Workflow

To set a password on an XLSX file with Sheetise, follow these steps:

  1. Initialise the Protector: Create an instance of SpreadsheetLocker.
  2. Configure Options: Set LockerSaveOptions with the desired password and protection flags (e.g., allow editing objects, allow printing).
  3. Define File Paths: Provide the source XLSX path and the destination protected XLSX location.
  4. Execute Protection: Call Protect with the prepared load and protection options.

Example – Protect an XLSX file with a password

using Sheetise;

var loadOptions = new LoadOptions
{
    InputFile = @"D:\Data\source.xlsx"
};

var saveOptions = new LockerSaveOptions
{
    OutputFile = @"D:\Data\protected.xlsx",
    Password = "Test"
};

SpreadsheetLocker.Process(loadOptions, saveOptions);

Example – Protect an XLSX file with a write‑protection password

using Sheetise;

var loadOptions = new LoadOptions
{
    InputFile = @"D:\Data\source.xlsx"
};

var saveOptions = new LockerSaveOptions
{
    OutputFile = @"D:\Data\protected.xlsx",
    PasswordOfWriteProtection = "Test"
};

SpreadsheetLocker.Process(loadOptions, saveOptions);

Expanded Format Support

  • Sheetise can also apply password protection to CSV, TSV and HTML exports generated from a workbook (the resulting files are wrapped in a ZIP with encryption).

With these capabilities, Sheetise makes XLSX password protection effortless, whether you need a quick one‑off script or a production‑grade service that secures thousands of spreadsheets daily.

 Українська