How to set password to Xlsm file

Sheetize XLSM Password Setter for .NET provides a simple yet powerful API for applying password protection to an Excel macro‑enabled workbook while preserving all worksheets, macros, 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 Password to XLSM

Encrypt an existing XLSM 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, images, and embedded macros 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

XLSM Password‑Protection Workflow

To set a password on an XLSM file with Sheetize, follow these steps:

  1. Initialize 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 XLSM path and the destination protected XLSM location.
  4. Execute Protection: Call Process with the prepared load and protection options.

Example – Protect an XLSM file with a password

using Sheetize;

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

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

SpreadsheetLocker.Process(loadOptions, saveOptions);

Example – Protect an XLSM file with a write protection password

using Sheetize;

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

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

SpreadsheetLocker.Process(loadOptions, saveOptions);

Expanded Format Support

  • Sheetize 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, Sheetize makes XLSM password protection effortless, whether you need a quick one‑off script or a production‑grade service that secures thousands of spreadsheets daily.

 English