Kuruluşlar hassas verileri depolamak ve paylaşmak için Excel’e giderek daha fazla güvenince, bu bilgilerin korunmasını sağlamak öncelikli. Aspose.Cells LowCode Spreadsheet Locker, en az kodlama çabası ile sağlam güvenlik önlemlerini uygulamanın kolay bir yolunu sağlar.

Bu makalede, Excel belgelerini güvence altına almak için Aspose.Cells kütüphanesini nasıl kullanacağınızı, temel dosya seviyesi korumasından daha gelişmiş çok katmanlı stratejilere ve paket işleme tekniklerine kadar her şeyi kapsamaktadır.

Aspose.Cells LowCode Spreadsheet Locker’ın Anahtar Özellikleri

  • File-Level Protection: Tüm dosyaları şifrelemek, şifre tabanlı erişimi kısıtlamak için.
  • Worksheet-Level Protection: Granüler güvenlik için çalışma sayfasında kullanıcı izinlerini kontrol edin.
  • Yapı Koruması: Çalışma kitabı yapıları ve düzenleri için yetkisiz değişiklikleri önlemek.
  • Batch İşleme: Çok sayıda Excel belgesinde otomatik koruma verimli.

Temel dosya seviyesi koruması

Çevrenizi geliştirin

Kodu içine dalmadan önce, projenizde Aspose.Cells yüklü olduğundan emin olun. NuGet Paket Yöneticisi aracılığıyla veya kütüphanesini resmi web sitesinden doğrudan indirebilirsiniz.

Temel Dosya Seviyesi Koruma için Örnek Kodu

public void ProtectExcelFile(string inputFile, string outputFile, string password)
{
    // Configure loading options
    LowCodeLoadOptions loadOptions = new LowCodeLoadOptions { InputFile = inputFile };
    
    // Configure saving options
    LowCodeSaveOptions saveOptions = new LowCodeSaveOptions {
        OutputFile = outputFile,
        SaveFormat = SaveFormat.Xlsx
    };
    
    // Apply file-level protection
    SpreadsheetLocker.Process(loadOptions, saveOptions, password, null);
}

Etiket: test ve doğrulama

Temel dosya seviyesi koruması uygulandıktan sonra, korunan dosyaların doğru şifre olmadan erişemeyeceğini doğrulamak önemlidir.

Örnek test fonksiyonu

public void ValidateFileProtection(string filePath)
{
    try
    {
        // Attempt to open the file with an incorrect password
        new Workbook(filePath, new LoadOptions { Password = "wrongpassword" });
        Console.WriteLine("Warning: File opened with incorrect password!");
    }
    catch (CellsException ex)
    {
        if (ex.Code == ExceptionType.IncorrectPassword)
            Console.WriteLine("Success: Incorrect password rejected.");
        else
            throw;
    }
}

Gelişmiş Koruma Stratejileri

Çok katmanlı koruma stratejisi

Bir çok katmanlı koruma stratejisinin uygulanması, kapsamlı güvenlik sağlamak için dosya düzeyinde şifreleme ve çalışma sayfası ve yapı korumaları ile birleştirilmesini içerir.

Multi-Layer Koruma Örnek Kodu

public void ApplyMultiLayerProtection(string inputFile, string outputFile, string filePassword)
{
    // Configure loading options
    LowCodeLoadOptions loadOptions = new LowCodeLoadOptions { InputFile = inputFile };
    
    using (Workbook workbook = new Workbook(inputFile))
    {
        // Protect workbook structure
        workbook.Settings.WriteProtection.SetPassword("StructurePassword");
        
        // Protect worksheets
        foreach (Worksheet worksheet in workbook.Worksheets)
            worksheet.Protect(ProtectionType.All, "SheetPassword", true);
        
        // Save the intermediate workbook
        workbook.Save("intermediate.xlsx");
    }
    
    LowCodeSaveOptions saveOptions = new LowCodeSaveOptions {
        InputFile = "intermediate.xlsx",
        OutputFile = outputFile,
        SaveFormat = SaveFormat.Xlsx
    };
    
    // Apply file-level encryption
    SpreadsheetLocker.Process(loadOptions, saveOptions, filePassword, null);
    
    if (File.Exists("intermediate.xlsx"))
        File.Delete("intermediate.xlsx");
}

Gelişme Raporlama ile Batch İşleme

Excel dosyalarının büyük sayısını içeren senaryolar için, paket işleme koruma sürecini önemli ölçüde kolaylaştırabilir.

Örnek Batch Koruma Kodu

public void BatchProtectExcelFiles(string[] inputFiles, string outputDirectory, string password)
{
    if (!Directory.Exists(outputDirectory))
        Directory.CreateDirectory(outputDirectory);
    
    int totalFiles = inputFiles.Length;
    int processedFiles = 0;
    int successCount = 0;
    int failCount = 0;
    
    foreach (string inputFile in inputFiles)
    {
        try
        {
            string fileName = Path.GetFileName(inputFile);
            string outputPath = Path.Combine(outputDirectory, $"Protected_{fileName}");
            
            LowCodeLoadOptions loadOptions = new LowCodeLoadOptions { InputFile = inputFile };
            LowCodeSaveOptions saveOptions = new LowCodeSaveOptions {
                OutputFile = outputPath,
                SaveFormat = SaveFormat.Xlsx
            };
            
            SpreadsheetLocker.Process(loadOptions, saveOptions, password, null);
            successCount++;
            Console.WriteLine($"Protected {fileName} successfully");
        }
        catch (Exception ex)
        {
            failCount++;
            Console.WriteLine($"Failed to protect {Path.GetFileName(inputFile)}: {ex.Message}");
        }
        
        processedFiles++;
        double progressPercentage = (double)processedFiles / totalFiles * 100;
        Console.WriteLine($"Progress: {progressPercentage:F1}% ({processedFiles}/{totalFiles})
    }
    
    Console.WriteLine($"Batch protection complete. Success: {successCount}, Failed: {failCount}");
}

Sonuç

Aspose.Cells LowCode Spreadsheet Locker’ı kullanarak, kuruluşlar Excel belgeleri için sağlam güvenlik önlemlerini en az kodlama çabasıyla uygulayabilirler. bu yaklaşım sadece belge güvenliği uygulamasını kolaylaştırmaz, aynı zamanda özel gereksinimlere dayalı koruma stratejilerini ayarlamak için esneklik sağlar.

Daha fazla bilgi ve örnekler için lütfen Aspose.Cells.LowCode API Referansı.

More in this category