Excel Dosyalarını Şifreleme

Microsoft Excel Kullanımı

Microsoft Excel’de (burada Microsoft Excel 2003) dosya şifreleme ayarlarını yapmak için:

  1. Araçlar menüsünden Seçenekler‘i seçin. Bir iletişim kutusu görünecektir.
  2. Güvenlik sekmesini seçin.
  3. Bir parola girin ve Gelişmiş‘i tıklayın.
  4. Şifreleme türünü seçin ve parolayı onaylayın.

Aspose.Cells ile Şifreleme

Aşağıdaki örnek, Aspose.Cells for Python via .NET API kullanarak bir Excel dosyasını nasıl şifreleyip parola koruma altına alacağınızı gösterir.

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")

Değiştirilecek Parolayı Belirtme Seçeneği

Aşağıdaki örnek, mevcut bir dosya için Aspose.Cells for Python via .NET API kullanarak Değiştirmek için Parola Microsoft Excel seçeneğinin nasıl ayarlanacağını gösterir.

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")

Şifrelenmiş dosyanın parolasını doğrulama

Şifreli dosyanın parolasını doğrulamak için, Aspose.Cells for Python via .NET, verify_password yöntemini sağlar. Bu yöntemler, iki parametre alır, dosya akışı ve doğrulanması gereken parola. Aşağıdaki kod parçası, sağlanan parolanın geçerli olup olmadığını doğrulamak için verify_password yönteminin nasıl kullanıldığını göstermektedir.

from aspose.cells import FileFormatUtil
# 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(".")
# Create a Stream object
fstream = open(dataDir + "EncryptedBook1.xlsx", "rb")
isPasswordValid = FileFormatUtil.verify_password(fstream, "1234")
print("Password is Valid: " + str(isPasswordValid))

ODS dosyasının Şifrelenmesi / Şifresinin Çözülmesi

Aspose.Cells for Python via .NET, ODS dosyasını şifreleyip şifresini çözmenize imkan tanır. Çözülen ODS dosyası hem Excel hem de OpenOffice’de açılabilir, ancak şifreli ODS dosyası yalnızca şifre girilerek OpenOffice tarafından açılabilir. Excel, şifreli ODS dosyasını açamaz ve uyarı mesajı gösterebilir. Şifreleme seçenekleri, diğer dosya türlerinin aksine, ODS dosyası için uygulanmaz. Bir ODS dosyasını şifrelemek için, dosyayı yükleyin ve kaydetmeden önce WorkbookSettings.password değerini gerçek şifre ile ayarlayın. Çıktı şifreli ODS dosyası yalnızca OpenOffice’te açılabilir.

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.
sourceDir = RunExamples.Get_SourceDirectory()
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
# Open an ODS file
workbook = Workbook(sourceDir + "sampleODSFile.ods")
# Password protect the file
workbook.settings.password = "1234"
# Save the ODS file
workbook.save(outputDir + "outputEncryptedODSFile.ods")

ODS dosyasını çözmek için, dosyayı yüklemek için LoadOptions.password ile bir parola sağlayın. Dosya yüklendikten sonra, WorkbookSettings.password dizesini null olarak ayarlayın.

from aspose.cells import LoadFormat, LoadOptions, 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.
sourceDir = RunExamples.Get_SourceDirectory()
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
# Open an encrypted ODS file
loadOptions = LoadOptions(LoadFormat.ODS)
# Set original password
loadOptions.password = "1234"
# Load the encrypted ODS file with the appropriate load options
workbook = Workbook(sourceDir + "sampleEncryptedODSFile.ods", loadOptions)
# Set the password to null
workbook.settings.password = None
# Save the decrypted ODS file
workbook.save(outputDir + "outputDecryptedODSFile.ods")