בעוד ארגונים יותר ויותר סומכים על Excel כדי לאחסן ולשתף נתונים רגישים, הבטחת מידע זה נשאר מוגן היא העיקרון.The Aspose.Cells LowCode Spreadsheet Locker מספק דרך פשוטה ליישם אמצעי אבטחה חזקים עם מאמץ הקוד מינימלי.

מאמר זה בוחן כיצד להשתמש בספריה Aspose.Cells כדי להבטיח את המסמכים של Excel, מכסה הכל מהגנה ברמת הקובץ הבסיסית לאסטרטגיות רב שכבות מתקדמות יותר וטכניקות עיבוד חבילות.

תכונות מרכזיות של Aspose.Cells LowCode Spreadsheet Locker

  • הגנה על רמה של קובץ: מצפנת את כל הקבצים כדי להגביל את הגישה המבוססת על סיסמאות.
  • הגנה ברמה של לוח העבודה: בקרת הרשאות המשתמש ברמת לוח העבודות על מנת להבטיח אבטחה חריפה.
  • הגנה על המבנה: למנוע שינויים בלתי מורשים במבנים ובמגוון של ספרי עבודה.
  • טיפול באץ: הגנה אוטומטית בין מספר מסמכים של Excel ביעילות.

הגנה ברמה הבסיסית של קובץ

הגדרת הסביבה שלך

לפני השקיעה בקוד, ודא שיש לך Aspose.Cells מותקן בפרויקט שלך.אתה יכול להוסיף אותו דרך NuGet Package Manager או על ידי הורדה הספרייה ישירות מהאתר הרשמי.

קוד דוגמה להגנה על רמה בסיסית של קובץ

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

קטגוריה: מבחן וזיהוי

לאחר יישום הגנה ברמת הקובץ הבסיסית, חשוב להוכיח כי הקבצים המוגנים אינם זמינים ללא הסיסמה הנכונה.

דוגמה למבחן תפקוד

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;
    }
}

אסטרטגיות הגנה מתקדמות

אסטרטגיית הגנה מרובה שכבות

יישום אסטרטגיית הגנה רב שכבה כרוך בשילוב של הצפנה ברמת הקבצים עם לוח העבודה והגנה מבנית כדי לספק אבטחה מקיפה.

קוד דוגמה להגנה מרובה שכבות

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

עיבוד Batch עם דיווח על התקדמות

עבור סקרינרים המעורבים במספר גדול של קבצי Excel, עיבוד קבוצה יכול להקל באופן משמעותי על תהליך ההגנה.

קוד דוגמה להגנה על Batch

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

מסקנה

באמצעות Aspose.Cells LowCode Spreadsheet Locker, ארגונים יכולים ליישם אמצעי אבטחה מוצקים עבור מסמכים Excel עם מאמץ הקוד מינימלי.

לקבלת מידע נוסף ודוגמאות נוספות, ראה Aspose.Cells.LowCode API רשימה.

More in this category