Dynamically Assemble Documents in .NET
手動での編集なしに、プログラムで table 構造を調整します。
ドキュメントアセンブリは、複数のWordテンプレートやファイルを動的にマージして統合されたドキュメントを作成することを指します。この手法は、レポート、提案書、または包括的な文書を生成する際に有用です。With Aspose.Words for .NET,、プログラムでこのプロセスを自動化できます。.
ステップ 2: 必要な名前空間をインポート
- インストールする .NET SDK お使いのオペレーティングシステム用に。.
- プロジェクトに Aspose.Words を追加:
dotnet add package Aspose.Words - マージする Word テンプレートやファイルを用意してください、たとえば
Template1.docx,Template2.docx,、そしてTemplate3.docx.
ステップ 4: テーブルにアクセスする
ドキュメントからインデックスでテーブルを取得する。
using System;
using Aspose.Words;
class Program
{
static void Main()
{
// Load individual Word templates
Document template1 = new Document("Template1.docx");
Document template2 = new Document("Template2.docx");
Document template3 = new Document("Template3.docx");
Console.WriteLine("Templates loaded successfully.");
}
}説明: このコードは、3つの別々のWord文書をメモリにロードします。.
テーブルから新しい行を作成するか、既存の行をクローンします。
using System;
using Aspose.Words;
class Program
{
static void Main()
{
Document masterDoc = new Document("Template1.docx");
// Append the other templates
Document template2 = new Document("Template2.docx");
Document template3 = new Document("Template3.docx");
masterDoc.AppendDocument(template2, ImportFormatMode.KeepSourceFormatting);
masterDoc.AppendDocument(template3, ImportFormatMode.KeepSourceFormatting);
Console.WriteLine("Templates merged successfully.");
}
}説明: このコードは、コンテンツを追加します Template2.docx と Template3.docx に Template1.docx,、元の書式を保持します。.
行にセルとテキストを追加します。
using System;
using Aspose.Words;
class Program
{
static void Main()
{
Document masterDoc = new Document("Template1.docx");
Document template2 = new Document("Template2.docx");
Document template3 = new Document("Template3.docx");
masterDoc.AppendDocument(template2, ImportFormatMode.KeepSourceFormatting);
masterDoc.AppendDocument(template3, ImportFormatMode.KeepSourceFormatting);
// Save the assembled document
masterDoc.Save("FinalAssembledDocument.docx");
masterDoc.Save("FinalAssembledDocument.pdf", SaveFormat.Pdf);
Console.WriteLine("Final assembled document saved.");
}
}説明: このコードは、結合されたドキュメントを Word (.docx) と target="_blank" rel="noopener">
PDF形式。.
RowCollection.Add を使用して、テーブルに行を追加します。
- 提案作成: - RowCollection.Insert を使用して特定のインデックスに行を挿入します。.
- 従業員オンボーディングキット: - 追加した行を含めてドキュメントを再保存します。.
- レポート作成: - 以下はテーブルに行を追加するための完全なコードです:.
このチュートリアルでは、C# を使用して MS Word ドキュメントのテーブルに行を追加する方法を示しました。これらの手順に従うことで、Word ドキュメント内のテーブルをプログラムで効果的に管理・変更できます。
- エンタープライズアプリケーション: - NuGet パッケージマネージャーを使用して Aspose.Words を .NET 用にインストールする.
- Webベースのプラットフォーム: - 文書内の特定の段落やコンテンツにコメントを追加する.
変更履歴を有効にして変更を記録する
- 書式の不一致: - 使用
ImportFormatMode.KeepSourceFormatting付属文書の書式を維持するために。. - ファイル破損エラー: - 一般的な問題と対処法.
- 大容量ファイルでのパフォーマンス: - 小さなバッチを段階的にマージしてメモリ使用量を最適化する。.
このガイドに従うことで、Aspose.Words を .NET 用に使用してドキュメントを動的に組み立て、ワークフローを合理化し、効率を向上させることができます。.