Encrypting Excel Files in 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#

 //Instantiate a Workbook object.

//Open an excel file.

Workbook workbook = new Workbook("Book1.xls");

//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("encryptedBook1.xls");

Download Running Code

Download Sample Code