Excel Dosyalarını Şifreleme

Microsoft Excel’i kullanma

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

  1. itibarenAraçlar menü, seçSeçeneklerBir iletişim kutusu görünecektir.
  2. seçinGüvenlik sekme.
  3. Bir şifre girin ve tıklayınGelişmiş
  4. Şifreleme türünü seçin ve parolayı onaylayın.

Aspose.Cells ile şifreleme

Aşağıdaki örnek, Aspose.Cells API kullanılarak bir excel dosyasının nasıl şifreleneceğini ve parolayla korunacağını gösterir.

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

Seçeneği değiştirmek için Parola Belirtme

Aşağıdaki örnek, nasıl ayarlanacağını gösterir.Değiştirilecek şifre Microsoft Aspose.Cells API’i kullanan mevcut bir dosya için Excel seçeneği.

// 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ğrulayın

Aspose.Cells for .NET, şifreli dosyanın parolasını doğrulamak için şu bilgileri sağlar:Parolayı Doğrula yöntem. Bu yöntemler, dosya akışı ve doğrulanması gereken parola olmak üzere iki parametreyi kabul eder. Aşağıdaki kod parçacığı,Parolayı Doğrula Sağlanan parolanın geçerli olup olmadığını doğrulama yöntemi.

// 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);

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

Aspose.Cells, ODS dosyasını şifrelemeye ve şifresini çözmeye izin verir. Şifresi çözülmüş ODS dosyası hem Excel’de hem de OpenOffice’te açılabilir, ancak şifreli ODS dosyası, şifre girildikten sonra yalnızca OpenOffice tarafından açılabilir. Excel, şifrelenmiş ODS dosyasını açamaz ve uyarı mesajı verebilir. Şifreleme seçenekleri, diğer dosya türlerinin aksine ODS dosyası için geçerli değildir. ODS dosyasını şifrelemek için dosyayı yükleyin veWorkbookSettings.Password kaydetmeden önce gerçek parolaya değer. Çıkış şifreli 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ın şifresini çözmek için, dosyayı bir parola girerek yükleyin.LoadOptions.Şifre . Dosya yüklendikten sonra,WorkbookSettings.Password null için dize.

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