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 API’sını kullanarak bir Excel dosyasını şifrelemek ve parolayla korumak için nasıl yapılacağını göstermektedir.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object.
// Open an excel file.
Workbook workbook = new Workbook(dataDir + "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(dataDir + "encryptedBook1.out.xls");

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

Aşağıdaki örnek, mevcut bir dosya için Aspose.Cells API’sını kullanarak Değiştirilecek Parolayı Microsoft Excel seçeneğini nasıl ayarlayacağını göstermektedir.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a Workbook object.
// Open an excel file.
Workbook workbook = new Workbook(dataDir + "Book1.xls");
// Set the password for modification.
workbook.Settings.WriteProtection.Password = "1234";
// Save the excel file.
workbook.Save(dataDir + "SpecifyPasswordToModifyOption.out.xls");

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

Şifrelenmiş dosyanın parolasını doğrulamak için, Aspose.Cells for .NET VerifyPassword yöntemini sağlar. Bu yöntemler, dosya akışını ve doğrulanması gereken parolayı kabul eder. Aşağıdaki kod parçası, sağlanan parolanın geçerli olup olmadığını doğrulamak için VerifyPassword yönteminin nasıl kullanıldığını göstermektedir.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create a Stream object
FileStream fstream = new FileStream(dataDir + "EncryptedBook1.xlsx", FileMode.Open);
bool isPasswordValid = FileFormatUtil.VerifyPassword(fstream, "1234");
Console.WriteLine("Password is Valid: " + isPasswordValid);

Aspose.Cells ile ODS dosyasının Şifrelenmesi/Şifresinin Çözülmesi

Aspose.Cells, ODS dosyasını şifrelemeye ve çözmeye izin verir. Çözülmüş ODS dosyası hem Excel hem de OpenOffice’te açılabilir, ancak şifrelenmiş ODS dosyası yalnızca OpenOffice tarafından parola sağlandıktan sonra açılabilir. Excel şifrelenmiş ODS dosyasını açamaz ve uyarı mesajı verebilir. Şifreleme seçenekleri diğer dosya türleri için geçerli değildir. ODS dosyasını şifrelemek için dosyayı yükleyin ve kaydetmeden önce WorkbookSettings.Password değerini gerçek parolaya ayarlayın. Çıkış şifrelenmiş ODS dosyası yalnızca OpenOffice’te açılabilir.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Open an ODS file
Workbook workbook = new 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.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Open an encrypted ODS file
Aspose.Cells.LoadOptions loadOptions = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Ods);
// Set original password
loadOptions.Password = "1234";
// Load the encrypted ODS file with the appropriate load options
Workbook workbook = new Workbook(sourceDir + "sampleEncryptedODSFile.ods", loadOptions);
// Set the password to null
workbook.Settings.Password = null;
// Save the decrypted ODS file
workbook.Save(outputDir + "outputDecryptedODSFile.ods");