How to set password to XLSX file
Sheetize 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 Password to 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 Sheetize, follow these steps:
- Initialize the Protector: Create an instance of
SpreadsheetLocker. - Configure Options: Set
LockerSaveOptionswith the desired password and protection flags (e.g., allow editing objects, allow printing). - Define File Paths: Provide the source XLSX path and the destination protected XLSX location.
- Execute Protection: Call
Protectwith the prepared load and protection options.
Example – Protect an XLSX file with a password
using Sheetize;
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 Sheetize;
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
- 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).s.
With these capabilities, Sheetize makes XLSX password protection effortless, whether you need a quick one‑off script or a production‑grade service that secures thousands of spreadsheets daily.