compare documents .net – .NET 開発者向け完全な GroupDocs.Comparison チュートリアル
If you need to compare documents .net programmatically, you’ve landed on the right guide.
Manually spotting differences between two versions of a contract, a spreadsheet, or a presentation can waste hours and still miss subtle changes. With GroupDocs.Comparison for .NET you can automate this task, generate visual diff reports, and even accept or reject changes without opening the files yourself. This tutorial walks you through every step—from installing the NuGet package to handling large‑scale folder comparisons—so you can embed reliable document comparison into any .NET solution.
クイック回答
- GroupDocs.Comparison の主な目的は何ですか? プログラムでドキュメントを比較し、変更を検出し、視覚的またはデータ駆動型の差分結果を生成することです。
- 変更を自動的に受け入れたり拒否したりできますか? はい—accept/reject API を使用して細かい制御を適用できます。
- ライブラリは .NET で画像比較をサポートしていますか? もちろんです。スクリーンショット、UI レンダリング、任意のラスタ画像を比較できます。
- フォルダー比較は可能ですか? はい—フォルダー全体を比較して、追加、削除、または変更されたファイルを検出できます。
- 開始前に何が必要ですか? .NET 開発環境、NuGet パッケージ、そして有効な GroupDocs.Comparison ライセンス(トライアル利用可能)です。
compare documents .net とは?
compare documents .net is the process of programmatically identifying differences between two or more document versions using a .NET library. GroupDocs.Comparison implements this by loading source and target files, applying configurable comparison options, and returning a ComparisonResult that contains both visual highlights and a structured list of changes. ComparisonResult represents the outcome of a comparison, containing the detected changes and visual diff data.
.NET 用 GroupDocs.Comparison を選ぶ理由
GroupDocs.Comparison supports over 50 formats, processes large PDFs in seconds, and includes enterprise‑grade features such as password handling, metadata preservation, and fine‑grained change management, eliminating the need for multiple specialized libraries and reducing development effort.
前提条件
- Visual Studio 2022 以降(または任意の .NET 対応 IDE)。
- .NET 6+ ランタイム(ライブラリは .NET Core 3.1 と .NET Framework 4.8 もサポート)。
- NuGet パッケージ
GroupDocs.Comparison(最新の安定版)。 - 有効なライセンスキー(30 日間のトライアルから開始可能)。
2 つのドキュメントを .net で比較するには?
To compare two documents .net, instantiate the Comparer class, call Compare(sourcePath, targetPath, outputPath), and specify any ComparisonOptions you need. The method creates a diff file that highlights insertions, deletions, and formatting changes, while also exposing a Changes collection for programmatic inspection. The Comparer object is the core engine that drives the comparison process.
手順ごとのウォークスルー
Comparerインスタンスを作成 – これは比較エンジンを駆動するコアオブジェクトです。- ソースとターゲットをロード – ファイルパス、ストリーム、またはバイト配列を渡せます。10 MB を超えるファイルはストリームの使用を推奨します。
- オプションを設定 – 大文字小文字を無視、パスワード設定、または
ComparisonOptionsで感度を調整できます。 - 比較を実行 –
Compareを呼び出し、視覚的差分の出力先を指定します。 - 結果を処理 –
Changesコレクションを読み取り、各変更を受け入れ、拒否、またはログに記録します。
GroupDocs.Comparison で比較できるフォーマットは?
GroupDocs.Comparison supports 50+ input and output formats, including DOCX, PDF, XLSX, PPTX, PNG, JPEG, BMP, and TIFF. It can also handle password‑protected files and files stored in cloud storage (via stream APIs). This breadth eliminates the need for multiple libraries when building a universal document‑processing pipeline.
プログラムで変更を受け入れまたは拒否するには?
The ComparisonResult object exposes a Changes collection. Each ChangeInfo item describes a single detected change and provides Accept() and Reject() methods. Call result.Changes.AcceptAll() to apply every detected change to the target document, or iterate result.Changes and invoke Accept() or Reject() on individual ChangeInfo objects for granular control. After applying the desired actions, save the updated document with result.Save(outputPath).
フォルダー全体を .net で比較するには?
Folder comparison involves iterating over matching file pairs and invoking the same Compare logic for each pair. GroupDocs.Comparison also offers a helper method CompareFolders(sourceFolder, targetFolder, outputFolder) that compares all matching files in two directories, detects added or removed files, and generates diff results. CompareFolders returns a collection of FolderComparisonResult objects, each indicating the status of a file pair and a link to its diff document.
.NET での画像比較はどのように機能しますか?
The image module treats each pixel as a data point, generating a diff image that highlights changed regions in red and returning a similarity score (0‑100 %). Call Comparer.CompareImages(imagePath1, imagePath2, outputPath); the engine aligns the images, computes per‑pixel differences, writes a diff image where altered pixels are colored, and provides a Similarity value you can use to trigger alerts or skip further processing if the change is below a threshold.
一般的なユースケース
- コード以外の資産のバージョン管理 – 契約書の改訂履歴を明確に保管します。
- 自動コンプライアンスチェック – ポリシードキュメントの無許可編集をフラグします。
- UI テスト用 CI/CD パイプライン – ビルド間でウェブページのスクリーンショットを比較します。
- バッチ移行プロジェクト – 変換されたファイルが元のコンテンツを保持しているか検証します。
大規模ドキュメント向けパフォーマンスのヒント
- ファイルをストリーム で処理し、メモリに完全にロードしないでください。これによりピーク RAM 使用量が最大 80 % 削減されます。
- 単一の
Comparerインスタンスを再利用 して複数の比較を行い、内部キャッシュを活用します。 ComparisonOptions.MemoryLimitを調整 して、500 MB 超のドキュメントでメモリ不足例外を防ぎます。
よくある質問
Q: How do I programmatically accept or reject changes after a comparison?
A: Use result.Changes.AcceptAll(), RejectAll(), or iterate each ChangeInfo and call Accept() / Reject() as needed, then save the document with result.Save(outputPath).
Q: Can I extract metadata such as author, creation date, or custom properties from documents?
A: Yes—DocumentInfo provides access to standard and custom metadata for both source and target files, allowing you to log or display this information.
Q: Is it possible to compare image files (e.g., PNG, JPEG) directly in .NET?
A: Absolutely. The CompareImages API highlights pixel‑level differences and returns a similarity percentage you can use in automated tests.
Q: How can I compare entire folders to find added, removed, or modified files?
A: Invoke Comparer.CompareFolders(sourceFolder, targetFolder, outputFolder); the method returns a collection of FolderComparisonResult objects that indicate the status of each file pair.
Q: What should I do if I need to compare password‑protected documents?
A: Supply the password via LoadOptions.Password when loading each document; the engine decrypts the files internally before performing the diff.
Q: Does GroupDocs.Comparison support .NET Core and .NET 5/6?
A: Yes—the library is compatible with .NET Core 3.1, .NET 5, .NET 6, and later, offering the same feature set across all runtimes.
信頼の指標
最終更新日: 2026-05-26
テスト環境: GroupDocs.Comparison 23.12 for .NET
作者: GroupDocs
追加チュートリアルリンク (unchanged)
ドキュメントとフォルダー比較
ドキュメント比較
ドキュメントのロードと保存
画像比較
基本的な使用法
クイックスタート
はじめに
ドキュメントのロード
基本比較
高度な比較
変更管理
ドキュメント情報
プレビュー生成
メタデータ管理
セキュリティと保護
ライセンスと構成
比較オプション
続きを読む 続きを読む 続きを読む 続きを読む 続きを読む 続きを読む はじめに ドキュメントのロード 基本比較 高度な比較 変更管理 ドキュメント情報 プレビュー生成 メタデータ管理 セキュリティと保護 ライセンスと構成 比較オプション クイックスタート はじめに ドキュメントとフォルダー比較 ドキュメント比較 ドキュメントのロードと保存 画像比較 基本的な使用法 クイックスタート はじめに ドキュメントのロード 基本比較 高度な比較 変更管理 ドキュメント情報 プレビュー生成 メタデータ管理 セキュリティと保護 ライセンスと構成 比較オプション