Dynamically Assemble Documents in .NET

手動での編集なしに、プログラムで table 構造を調整します。

ドキュメントアセンブリは、複数のWordテンプレートやファイルを動的にマージして統合されたドキュメントを作成することを指します。この手法は、レポート、提案書、または包括的な文書を生成する際に有用です。With Aspose.Words for .NET,、プログラムでこのプロセスを自動化できます。.

ステップ 2: 必要な名前空間をインポート

  1. インストールする .NET SDK お使いのオペレーティングシステム用に。.
  2. プロジェクトに Aspose.Words を追加: dotnet add package Aspose.Words
  3. マージする 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.docxTemplate3.docxTemplate1.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 を使用して、テーブルに行を追加します。

  1. 提案作成: - RowCollection.Insert を使用して特定のインデックスに行を挿入します。.
  2. 従業員オンボーディングキット: - 追加した行を含めてドキュメントを再保存します。.
  3. レポート作成: - 以下はテーブルに行を追加するための完全なコードです:.

このチュートリアルでは、C# を使用して MS Word ドキュメントのテーブルに行を追加する方法を示しました。これらの手順に従うことで、Word ドキュメント内のテーブルをプログラムで効果的に管理・変更できます。

  1. エンタープライズアプリケーション: - NuGet パッケージマネージャーを使用して Aspose.Words を .NET 用にインストールする.
  2. Webベースのプラットフォーム: - 文書内の特定の段落やコンテンツにコメントを追加する.

変更履歴を有効にして変更を記録する

  1. 書式の不一致: - 使用 ImportFormatMode.KeepSourceFormatting 付属文書の書式を維持するために。.
  2. ファイル破損エラー: - 一般的な問題と対処法.
  3. 大容量ファイルでのパフォーマンス: - 小さなバッチを段階的にマージしてメモリ使用量を最適化する。.

このガイドに従うことで、Aspose.Words を .NET 用に使用してドキュメントを動的に組み立て、ワークフローを合理化し、効率を向上させることができます。.

 日本語