Encrypting Excel Files with Go

Using Microsoft Excel

To set file encryption settings in Microsoft Excel (for example, Microsoft Excel 2003):

  1. From the Tools menu, select Options. A dialog will appear.
  2. Select the Security tab.
  3. Input a password and click Advanced.
  4. Choose the encryption type and confirm the password.

Encryption with Aspose.Cells

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

Specifying Password to Modify Option

The following example shows how to set the Password to modify Microsoft Excel option for an existing file using the Aspose.Cells API.

Verify the Password of the Encrypted File

To verify the password of the encrypted file, Aspose.Cells for Go provides the VerifyPassword method. This method accepts two parameters: the file stream and the password that needs to be verified. The following code snippet demonstrates the use of the VerifyPassword method to verify whether the provided password is valid or not.

Encryption/Decryption of ODS Files with Aspose.Cells

Aspose.Cells allows you to encrypt and decrypt ODS files. Decrypted ODS files can be opened both in Excel and OpenOffice; however, encrypted ODS files can only be opened by OpenOffice after providing the password. Excel cannot open the encrypted ODS file and may raise a warning message. The encryption options are not applicable for ODS files, unlike other file types. For encrypting an ODS file, load the file and set the WorkbookSettings.GetPassword() value to the actual password before saving it. The output encrypted ODS file can be opened in OpenOffice only.

For decrypting an ODS file, load the file by providing a password in the LoadOptions.GetPassword(). Once the file is loaded, set the WorkbookSettings.GetPassword() string to nullptr.