HTML JPG PDF XML XLS
Aspose.Cells  for .NET
XLS

Encrypt XLS Files via C#

Password-protect Excel spreadsheets including XLS format using .NET Library.

How to Protect XLS File Using C#

In order to protect XLS file, we’ll use

Aspose.Cells for .NET

API which is a feature-rich, powerful and easy to use document protection API for C# platform. Open

NuGet

package manager, search for Aspose.Cells and install. You may also use the following command from the Package Manager Console.

Aspose.Cells


PM> Install-Package Aspose.Cells

Protect XLS via C#

You need

aspose.cells.dll

referenced in your project to execute the following workflow.

  1. Instantiate Workbook class with path to XLS file
  2. Get the default or any Worksheet to add protection
  3. Protect Worksheet with Worksheet.Protect method
  4. Protect Workbook with Workbook.Protect method
  5. Save result in XLS format

System Requirements

Aspose.Cells for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Mono or Xamarin Platforms
  • Development environment like Microsoft Visual Studio
  • Add reference to the Aspose.Cells for .NET DLL in your project
 

Command


// load the XLS Excel file 
var book = new Aspose.Cells.Workbook("unlocked.xls");

// access the first worksheet
var worksheet = book.Worksheets[0];

// protect the worksheet with password
worksheet.Protect(Aspose.Cells.ProtectionType.All, "password", null);

// protect the whole workbook with password
book.Protect(Aspose.Cells.ProtectionType.All, "password");

// save the modified file in default format
book.Save("protected.xls");
 
  • About Aspose.Cells for .NET API

    Aspose.Cells API can be used to create, edit, convert and render Microsoft Excel formats to different formats. Moreover, it can be used for comprehensive charting, scalable reporting and reliable calculations within software applications. Aspose.Cells is a standalone API and it does not require any software like Microsoft or OpenOffice.

    Free App to Protect XLS

    Other Supported Protection Formats

    Using C#, one can easily protect other formats including.

    ODS (OpenDocument Spreadsheet File)
    XLSB (Binary Excel Workbook File)
    XLSM (Spreadsheet File)
    XLSX (OOXML Excel File)