조직이 점점 더 민감한 데이터를 저장하고 공유하기 위해 Excel에 의존하기 때문에이 정보가 보호되고 있는지 확인하는 것이 우선 순위입니다.The Aspose.Cells LowCode Spreadsheet Locker는 최소한의 코딩 노력으로 강력한 보안 조치를 실행하는 간단한 방법을 제공합니다.
이 기사에서는 Aspose.Cells 도서관을 사용하여 기본 파일 수준 보호에서 더 고급 다층 전략 및 배치 처리 기술에 이르기까지 모든 것을 다루는 Excel 문서를 보장하는 방법을 조사합니다.
Aspose.Cells LowCode Spreadsheet Locker의 핵심 기능
- File-Level Protection: 전체 파일을 암호화하여 비밀번호를 기반으로 접근을 제한합니다.
- Worksheet-Level Protection: 작업장 수준에서 사용자 권한을 제어하여 그라너 보안을 제공합니다.
- ** 구조 보호:** 워크북 구조 및 배치에 대한 허가되지 않은 변경을 방지합니다.
- Batch 처리: 효과적으로 여러 Excel 문서를 통해 자동으로 보호합니다.
기본 파일 수준 보호
당신의 환경을 정리하라
코드에 몰입하기 전에 프로젝트에 Aspose.Cells가 설치되어 있는지 확인하십시오.NuGet 패키지 매니저를 통해 추가하거나 공식 웹 사이트에서 라이브러리를 직접 다운로드하여 추가할 수 있습니다.
기본 파일 수준 보호를 위한 예제 코드
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);
}
Subsection: 테스트 및 검증
기본 파일 수준 보호를 구현한 후에는 보호된 파일이 올바른 암호없이 액세스할 수 없다는 것을 확인하는 것이 중요합니다.이 행동을 확인하기 위해 간단한 테스트 기능을 사용하십시오.
샘플 테스트 기능
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;
}
}
고급 보호 전략
멀티 레이어 보호 전략
다층 보호 전략의 구현은 포괄적 인 보안을 제공하기 위해 워크시트 및 구조 보호와 파일 수준 암호화를 결합하는 것을 포함합니다.
모델 번호:Multi-Layer Protection
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");
}
진행 보고서와 함께 배치 처리
Excel 파일의 큰 숫자를 포함하는 시나리오의 경우, 배치 처리는 보호 프로세스를 상당히 단순화 할 수 있습니다.
배치 보호에 대한 예제 코드
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 참조.