Crittografa e Decrittografa file Excel

Utilizzando Microsoft Excel

Per impostare le impostazioni di crittografia del file in Microsoft Excel (qui Microsoft Excel 2003):

  1. Dal menu Strumenti, seleziona Opzioni. Verrà visualizzata una finestra di dialogo.
  2. Selezionare la scheda Sicurezza.
  3. Immetti una password e clicca su Avanzate
  4. Scegliere il tipo di crittografia e confermare la password.

Crittare file Excel con Aspose.Cells

Il seguente esempio mostra come criptografare e proteggere con password un file excel utilizzando l’API Aspose.Cells per Python via .NET.

from aspose.cells import EncryptionType, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a Workbook object.
# Open an excel file.
workbook = Workbook(dataDir + "Book1.xls")
# Specify XOR encryption type.
workbook.set_encryption_options(EncryptionType.XOR, 40)
# Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider).
workbook.set_encryption_options(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128)
# Password protect the file.
workbook.settings.password = "1234"
# Save the excel file.
workbook.save(dataDir + "encryptedBook1.out.xls")

Specificare la password per modificare l’opzione

Il seguente esempio mostra come impostare l’opzione Password per modificare di Microsoft Excel per un file esistente usando l’API Aspose.Cells per Python via .NET.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a Workbook object.
# Open an excel file.
workbook = Workbook(dataDir + "Book1.xls")
# Set the password for modification.
workbook.settings.write_protection.password = "1234"
# Save the excel file.
workbook.save(dataDir + "SpecifyPasswordToModifyOption.out.xls")

Decrittografare un file Excel con Aspose.Cells

È molto semplice aprire un file excel protetto da password e decifrarlo usando l’API Aspose.Cells per Python via .NET come nei seguenti codici:

from aspose.cells import LoadOptions, Workbook
# Open encrypted file with password.
loadOptions = LoadOptions()
loadOptions.password = "password"
workbook = Workbook("Book1.xlsx", loadOptions)
# Remove password.
workbook.settings.password = None
# Save the file.
workbook.save("Book1.xlsx")

Argomenti avanzati