Encrypting Excel Files using Aspose.Cells

Using Microsoft Excel

To set file encryption settings in Microsoft Excel (here Microsoft Excel 2003):

  1. From the Tools menu, select Options. A dialog appears.
  2. Select the Security tab.
  3. Input a password and click Advanced Options dialog

todo:image_alt_text

  1. Choose the encryption type and confirm the password.

    Encryption Type dialog

todo:image_alt_text

Encryption with Aspose.Cells

The following example shows how to encrypt and password protect an excel file using the Aspose.Cells API.

C#

 string FilePath = @"..\..\..\Sample Files\";

string srcFileName = FilePath + "Encrypting Excel Files.xlsx";

string destFileName = FilePath + "Result Encrypting Excel Files.xlsx";

//Open an excel file.

Workbook workbook = new Workbook(srcFileName);

//Specify XOR encryption type.

workbook.SetEncryptionOptions(EncryptionType.XOR, 40);

//Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider).

workbook.SetEncryptionOptions(EncryptionType.StrongCryptographicProvider, 128);

//Password protect the file.

workbook.Settings.Password = "1234";

//Save the excel file.

workbook.Save(destFileName);

Download Running Code

Download Sample Code