NuGet을 통해 설치됨
PM> Install-Package Spire.Doc
관련된 링크들
직장에서 두 가지 버전의 Word 문서를 받고 그 사이의 차이점을 찾아야 하는 필요성에 직면하는 것은 드문 일이 아닙니다. 문서 비교는 법률, 규정 및 교육 분야에서 특히 중요하고 널리 사용됩니다. 이 기사에서는 다음을 수행하는 방법을 배웁니다 C# 및 VB.NET에서 두 개의 Word 문서 비교 사용하여 Spire.Doc for .NET.
아래는 비교할 두 Word 문서의 스크린샷입니다.

Spire.Doc for .NET 설치
먼저 Spire.Doc for .NET 패키지에 포함된 DLL 파일을 .NET 프로젝트의 참조로 추가해야 합니다. DLL 파일은 이 링크에서 다운로드하거나 NuGet을 통해 설치할 수 있습니다.
PM> Install-Package Spire.Doc
두 문서를 비교하고 결과를 세 번째 Word 문서에 저장
비교 결과를 별도의 Word 문서에 저장하면 삽입, 삭제 및 서식 수정을 포함하여 원본 문서의 모든 변경 사항을 볼 수 있습니다. 다음은 두 문서를 비교하고 Spire.Doc for .NET 사용하여 세 번째 Word 문서에 결과를 저장하는 단계입니다.
- 문서 개체를 초기화하는 동안 두 개의 Word 문서를 개별적으로 로드합니다.
- Document.Compare() 메서드를 사용하여 이 두 문서를 비교합니다.
- ;Document.SaveToFile() 메서드를 사용하여 결과를 세 번째 Word 문서에 저장합니다.
- C#
- VB.NET
using Spire.Doc;
namespace CompareDocuments
{
class Program
{
static void Main(string[] args)
{
//Load one Word document
Document doc1 = new Document("C:\\Users\\Administrator\\Desktop\\original.docx");
//Load the other Word document
Document doc2 = new Document("C:\\Users\\Administrator\\Desktop\\revised.docx");
//Compare two documents
doc1.Compare(doc2, "John");
//Save the differences in a third document
doc1.SaveToFile("Differences.docx", FileFormat.Docx2013);
doc1.Dispose();
}
}
}

두 문서를 비교하고 목록에서 삽입 및 삭제 반환
개발자는 전체 차이점 대신 삽입 및 삭제만 얻기를 원할 수 있습니다. 다음은 두 개의 개별 목록에서 삽입 및 삭제를 가져오는 단계입니다.
- 문서 개체를 초기화하는 동안 두 개의 Word 문서를 개별적으로 로드합니다.
- Document.Compare() 메서드를 사용하여 두 문서를 비교합니다.
- DifferRevisions 클래스의 생성자 함수를 사용하여 수정본을 가져옵니다.
- DifferRevisions.InsertRevisions 속성을 통해 삽입 목록을 가져옵니다.
- DifferRevisions.DeleteRevisions 속성을 통해 삭제 목록을 가져옵니다.
- 두 목록의 요소를 반복하여 특정 삽입 및 삭제를 얻습니다.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Fields;
using System;
namespace GetDifferencesInList
{
class Program
{
static void Main(string[] args)
{
//Load one Word document
Document doc1 = new Document("C:\\Users\\Administrator\\Desktop\\original.docx");
//Load the other Word document
Document doc2 = new Document("C:\\Users\\Administrator\\Desktop\\revised.docx");
//Compare the two Word documents
doc1.Compare(doc2, "Author");
//Get the revisions
DifferRevisions differRevisions = new DifferRevisions(doc1);
//Return the insertion revisions in a list
var insetRevisionsList = differRevisions.InsertRevisions;
//Return the deletion revisions in a list
var deletRevisionsList = differRevisions.DeleteRevisions;
//Create two int variables
int m = 0;
int n = 0;
//Loop through the insertion revision list
for (int i = 0; i < insetRevisionsList.Count; i++)
{
if (insetRevisionsList[i] is TextRange)
{
m += 1;
//Get the specific revision and get its content
TextRange textRange = insetRevisionsList[i] as TextRange;
Console.WriteLine("Insertion #" + m + ":" + textRange.Text);
}
}
Console.WriteLine("=====================");
//Loop through the deletion revision list
for (int i = 0; i < deletRevisionsList.Count; i++)
{
if (deletRevisionsList[i] is TextRange)
{
n += 1;
//Get the specific revision and get its content
TextRange textRange = deletRevisionsList[i] as TextRange;
Console.WriteLine("Deletion #" + n + ":" + textRange.Text);
}
}
Console.ReadKey();
}
}
}

임시 면허 신청
생성된 문서에서 평가 메시지를 제거하거나 기능 제한을 제거하려면 다음을 수행하십시오 30일 평가판 라이선스 요청 자신을 위해.