스프레드시트 버전 간의 변경 사항을 분석하는 것은 재무, 보고 및 데이터‑검증 워크플로에서 일상적인 작업입니다. GroupDocs.Comparison Cloud SDK for .NET은 .NET에서 수동 검토 없이 Excel 파일을 쉽게 비교할 수 있는 강력한 API를 제공합니다. 이 가이드에서는 라이브러리를 설정하고, 워크북을 업로드하며, C#에서 REST 엔드포인트를 호출하고, 상세 변경 정보를 검색하고, 정확한 결과를 위해 비교 옵션을 미세 조정하는 방법을 보여줍니다.
시작하기 전에: 전제 조건 및 설치
시작하기 전에 다음을 확인하십시오:
- .NET 6.0 이상이 설치되어 있어야 합니다.
- Visual Studio 2022와 같은 IDE.
- ClientId 및 ClientSecret가 포함된 GroupDocs Cloud 계정.
- Excel 파일을 업로드할 GroupDocs Cloud 스토리지에 대한 액세스.
NuGet을 통해 SDK를 설치합니다:
dotnet add package GroupDocs.Comparison-Cloud
최신 패키지를 release page에서 다운로드하십시오. 설치 후, 나중에 보여지는 대로 코드에 자격 증명을 추가하십시오. 이제 비교 워크플로를 시작할 준비가 되었습니다.
.NET에서 Excel 파일 비교 단계별 가이드
.NET에서 SDK를 사용하여 Excel 파일을 비교하는 단계는 다음과 같습니다.
1단계: 원본 및 대상 문서 로드
자격 증명을 사용하여 구성 객체를 생성하고 CompareApi를 인스턴스화합니다.
var config = new Configuration
{
ClientId = "YOUR_CLIENT_ID",
ClientSecret = "YOUR_CLIENT_SECRET"
};
var compareApi = new CompareApi(config);
단계 2: Excel 워크북 준비
소스 및 대상 XLSX 파일을 가리키는 FileInfo 객체를 정의하고, 이 파일들은 GroupDocs Cloud 스토리지에 저장됩니다.
var sourceFile = new FileInfo { FilePath = "input/source.xlsx" };
var targetFile = new FileInfo { FilePath = "input/target.xlsx" };
3단계: 비교 옵션 및 설정 지정
자세한 변경 설정을 포함하여 CompareOptions 객체를 구성합니다.
var compareOptions = new CompareOptions
{
SourceFile = sourceFile,
TargetFiles = new List<FileInfo> { targetFile },
OutputPath = "output/diff_result.xlsx",
Settings = new Settings
{
ShowDeletedContent = true,
ShowInsertedContent = true,
ShowStyleChanges = true,
GenerateSummaryPage = true
}
};
전체 설정 목록은 API 참조를 참조하십시오.
4단계: 비교 실행 및 결과 처리
Compare 메서드를 호출하고 기본 결과 정보를 읽습니다.
var compareResult = compareApi.Compare(compareOptions);
Console.WriteLine($"Comparison completed. Result file: {compareResult.Path}");
Console.WriteLine($"Number of changes detected: {compareResult.Changes?.Count ?? 0}");
5단계: 상세 변경 정보 가져오기
세부 보고서가 필요하면 GetChanges 요청을 사용하십시오.
var changesRequest = new GetChangesRequest
{
SourceFile = sourceFile,
TargetFile = targetFile,
OutputPath = "output/detailed_changes.json"
};
var detailedChanges = compareApi.GetChanges(changesRequest);
Console.WriteLine($"Detailed changes saved to: {detailedChanges.Path}");
이러한 단계들을 통해 .NET에서 Excel 파일 비교 프로세스를 완전히 자동화했습니다.
프로그래밍으로 Excel 파일 비교 - 전체 코드 예제
다음 코드는 구성부터 결과 처리까지 전체 워크플로를 보여줍니다.
using System;
using System.Collections.Generic;
using GroupDocs.Comparison.Cloud.Sdk.Api;
using GroupDocs.Comparison.Cloud.Sdk.Client;
using GroupDocs.Comparison.Cloud.Sdk.Model;
namespace CompareExcelDemo
{
class Program
{
static void Main(string[] args)
{
// Set up API credentials (replace with your actual credentials)
var config = new Configuration
{
ClientId = "YOUR_CLIENT_ID",
ClientSecret = "YOUR_CLIENT_SECRET"
};
// Initialize Compare API
var compareApi = new CompareApi(config);
// Prepare source and target Excel files (must be uploaded to GroupDocs Cloud storage beforehand)
var sourceFile = new FileInfo { FilePath = "input/source.xlsx" };
var targetFile = new FileInfo { FilePath = "input/target.xlsx" };
// Define comparison options
var compareOptions = new CompareOptions
{
SourceFile = sourceFile,
TargetFiles = new List<FileInfo> { targetFile },
OutputPath = "output/diff_result.xlsx",
// Optional: specify that we want detailed changes for worksheets
Settings = new Settings
{
ShowDeletedContent = true,
ShowInsertedContent = true,
ShowStyleChanges = true,
GenerateSummaryPage = true
}
};
try
{
// Call the Compare API
var compareResult = compareApi.Compare(compareOptions);
// Output basic result information
Console.WriteLine($"Comparison completed. Result file: {compareResult.Path}");
Console.WriteLine($"Number of changes detected: {compareResult.Changes?.Count ?? 0}");
// Iterate through change details
if (compareResult.Changes != null)
{
foreach (var change in compareResult.Changes)
{
Console.WriteLine("--------------------------------------------------");
Console.WriteLine($"Change Type : {change.ChangeType}");
Console.WriteLine($"Worksheet : {change.Worksheet}");
Console.WriteLine($"Cell Address : {change.CellAddress}");
Console.WriteLine($"Old Value : {change.OldValue}");
Console.WriteLine($"New Value : {change.NewValue}");
Console.WriteLine($"Is New Row : {change.IsNewRow}");
Console.WriteLine($"Is New Column : {change.IsNewColumn}");
}
}
// Retrieve detailed changes via GetChanges (optional)
var changesRequest = new GetChangesRequest
{
SourceFile = sourceFile,
TargetFile = targetFile,
OutputPath = "output/detailed_changes.json"
};
var detailedChanges = compareApi.GetChanges(changesRequest);
Console.WriteLine($"Detailed changes saved to: {detailedChanges.Path}");
}
catch (ApiException apiEx)
{
Console.WriteLine($"API error: {apiEx.ErrorCode} - {apiEx.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
}
}
}
참고: 이 코드 예제는 핵심 기능을 보여줍니다. 프로젝트에서 사용하기 전에 파일 경로와 구성 값을 실제 환경에 맞게 업데이트하고, 모든 필수 종속성이 올바르게 설치되었는지 확인하며, 개발 환경에서 충분히 테스트하십시오. 문제가 발생하면 공식 문서를 참조하거나 지원 팀에게 문의하십시오.
cURL을 사용한 REST 기반 Excel 비교 수행
C# 코드를 작성하지 않고 REST API를 직접 호출하여 동일한 결과를 얻을 수 있습니다.
1. 인증 및 액세스 토큰 가져오기
curl -X POST "https://api.groupdocs.cloud/v1.0/oauth2/token" \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
2. 소스 워크북 업로드
curl -X PUT "https://api.groupdocs.cloud/v1.0/storage/file?path=input/source.xlsx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-T "./source.xlsx"
3. 대상 워크북 업로드
curl -X PUT "https://api.groupdocs.cloud/v1.0/storage/file?path=input/target.xlsx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-T "./target.xlsx"
4. 비교 실행
curl -X POST "https://api.groupdocs.cloud/v1.0/comparison/compare" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"source_file": {"file_path":"input/source.xlsx"},
"target_files": [{"file_path":"input/target.xlsx"}],
"output_path":"output/diff_result.xlsx",
"settings": {
"show_deleted_content": true,
"show_inserted_content": true,
"show_style_changes": true,
"generate_summary_page": true
}
}'
5. 결과 차이 워크북 다운로드
curl -X GET "https://api.groupdocs.cloud/v1.0/storage/file?path=output/diff_result.xlsx" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o diff_result.xlsx
전체 매개변수 목록은 공식 API 문서를 참조하십시오.
결론
GroupDocs.Comparison Cloud SDK for .NET을 사용하면 .NET에서 Excel 파일을 쉽게 비교하고 모든 수정 사항을 강조 표시하는 상세한 diff 워크북을 얻을 수 있습니다. SDK의 REST 기반 아키텍처를 통해 최소한의 노력으로 C# 서비스, 웹 API 또는 백그라운드 작업에 스프레드시트 비교 기능을 통합할 수 있습니다. 프로덕션 사용을 위해 적절한 라이선스를 획득해야 함을 기억하세요; 임시 라이선스는 라이선스 페이지에서 제공되며 전체 라이선스 세부 정보는 제품 사이트에 나와 있습니다. 오늘 바로 Excel diff 워크플로를 자동화하여 수동 검사 오류를 없애세요.
자주 묻는 질문
.NET에서 많은 코드를 작성하지 않고 Excel 파일을 비교하려면 어떻게 해야 하나요?
SDK가 복잡한 작업을 추상화합니다. 자격 증명을 구성하고 두 개의 XLSX 파일을 지정한 다음compareApi.Compare를 호출하기만 하면 됩니다. 라이브러리는 차이 파일과 변경 객체 목록을 반환합니다.What format does the diff result use?
기본적으로 결과는 XLSX 워크북으로 저장되며, 원본 레이아웃을 유지하면서 삭제, 삽입 및 스타일 변경에 대한 시각적 표시를 적용합니다.보호된 Excel 워크북을 비교할 수 있나요?
예.FileInfo객체의Password속성에 비밀번호를 제공하십시오. API가 비교를 수행하기 전에 워크북의 잠금을 해제합니다.개발 및 테스트에 라이선스가 필요합니까?
임시 라이선스는 라이선스 페이지에서 얻을 수 있습니다. 프로덕션 배포의 경우 제품 페이지에 설명된 대로 정식 라이선스를 구매해야 합니다.
