Getting Started with IronWord

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronWord: .NET のための Word ドキュメント ライブラリ

IronWord は Iron Software によって開発された Word ドキュメント ライブラリです。 IronWord は .NET アプリケーションで Word ドキュメントを扱うための強力な機能を提供します。

  • Word および Docx ドキュメントの読み込み、操作、保存。
  • PageSetup: 用紙サイズ、ページの向き、余白、背景色の設定。
  • TextRun: テキストコンテンツ、スタイルの処理、テキストの分割、追加、画像の追加。
  • TextStyle: フォントの種類、サイズ、色、太字、斜体、打ち消し線、下線、上付き、下付きの管理。
  • Paragraph: テキストラン、画像、図形の追加、スタイル、配置、箇条書き、番号付きリストの設定。
  • Table: 表の構造の操作、行の追加、セルの値の取得と設定、行の削除、セルの結合など。
  • Image: ファイルまたはストリームからの画像の読み込み、テキストの折り返し、位置オフセット、幅、高さ、およびその他のプロパティの設定。
  • Shape: テキストの折り返し、位置オフセット、幅、高さ、形状タイプ、回転の設定。
class="hsg-featured-snippet">

.NET のための Word ドキュメント C# ライブラリ

  1. DOCX ドキュメントを扱うための C# ライブラリのダウンロード
  2. Word および DOCX ドキュメントの作成と修正
  3. 段落、セクション、表などのドキュメント構造の追加
  4. テキストラン、画像、図形などのドキュメント要素の追加
  5. 簡単にドキュメント要素をスタイリング

インストール

IronWord ライブラリ

IronWord のインストールは迅速かつ簡単です。 次のコマンドを使用して NuGet からパッケージをインストールできます。

Install-Package IronWord

または、公式 IronWord NuGet サイトから直接ダウンロードします。

インストール後は、C# コードファイルの先頭に using IronWord; を追加することで始められます。

ライセンスキーの適用

次に、License クラスの LicenseKey プロパティにライセンスキーを割り当てることで、有効なライセンスまたは試用キーを IronWord に適用します。 インポート文の直後、任意の IronWord メソッドを使用する前に、次のコードを含めてください。

using IronWord;

// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";
using IronWord;

// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";
Imports IronWord

' Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"
$vbLabelText   $csharpLabel

コード例

いくつかのコード例と利用可能な機能を探りましょう。

[{i:(IronWord によって生成された DOCX ファイルは、特定のバージョンの Microsoft Word で開くと 互換モード になり、いくつかのスタイリングが利用できません)」 Word ドキュメントを互換モードから変換するには)

  1. 「ファイル」 > 「情報」を選択し、「変換」をクリックします。
  2. ドキュメントが最新のファイル形式にアップグレードされるというメッセージが表示されます。 「OK」をクリックしてください。

Word および Docx ドキュメントの作成

WordDocument クラスのいずれかのコンストラクタを使用して Word ドキュメントを作成します。 その後、SaveAs メソッドを使用して Word ドキュメントをエクスポートします。 例:

using IronWord;

class Program
{
    static void Main()
    {
        // Create a new Word document
        var document = new WordDocument();

        // Save the document as a .docx file
        document.SaveAs("example.docx");
    }
}
using IronWord;

class Program
{
    static void Main()
    {
        // Create a new Word document
        var document = new WordDocument();

        // Save the document as a .docx file
        document.SaveAs("example.docx");
    }
}
Imports IronWord

Friend Class Program
	Shared Sub Main()
		' Create a new Word document
		Dim document = New WordDocument()

		' Save the document as a .docx file
		document.SaveAs("example.docx")
	End Sub
End Class
$vbLabelText   $csharpLabel

画像の追加

画像はそれ自体では追加できません; 代わりに、ParagraphTableCell、または Section などのドキュメント構造のいずれかに追加する必要があります。 AddImage メソッドを使用して画像を追加します。 例:

using IronWord;
using System.Drawing;

class Program
{
    static void Main()
    {
        var document = new WordDocument();
        var section = document.Sections.Add();

        // Add an image to a paragraph
        var paragraph = section.Paragraphs.Add();
        paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100));

        document.SaveAs("example_with_image.docx");
    }
}
using IronWord;
using System.Drawing;

class Program
{
    static void Main()
    {
        var document = new WordDocument();
        var section = document.Sections.Add();

        // Add an image to a paragraph
        var paragraph = section.Paragraphs.Add();
        paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100));

        document.SaveAs("example_with_image.docx");
    }
}
Imports IronWord
Imports System.Drawing

Friend Class Program
	Shared Sub Main()
		Dim document = New WordDocument()
		Dim section = document.Sections.Add()

		' Add an image to a paragraph
		Dim paragraph = section.Paragraphs.Add()
		paragraph.AddImage("path/to/image.jpg", New Rectangle(0, 0, 100, 100))

		document.SaveAs("example_with_image.docx")
	End Sub
End Class
$vbLabelText   $csharpLabel

表の追加

表を追加するには、表、行、列、および表セルの作成が必要です。 これにより、各セルに異なるスタイルを持たせることができるため、重要な構成の機会が得られます。 例:

using IronWord;

class Program
{
    static void Main()
    {
        var document = new WordDocument();
        var section = document.Sections.Add();
        var table = section.Tables.Add(3, 3); // 3x3 table

        // Iterate over cells and set their content
        for (int i = 0; i < table.Rows.Count; i++)
        {
            for (int j = 0; j < table.Rows[i].Cells.Count; j++)
            {
                table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}");
            }
        }

        document.SaveAs("example_with_table.docx");
    }
}
using IronWord;

class Program
{
    static void Main()
    {
        var document = new WordDocument();
        var section = document.Sections.Add();
        var table = section.Tables.Add(3, 3); // 3x3 table

        // Iterate over cells and set their content
        for (int i = 0; i < table.Rows.Count; i++)
        {
            for (int j = 0; j < table.Rows[i].Cells.Count; j++)
            {
                table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}");
            }
        }

        document.SaveAs("example_with_table.docx");
    }
}
Imports IronWord

Friend Class Program
	Shared Sub Main()
		Dim document = New WordDocument()
		Dim section = document.Sections.Add()
		Dim table = section.Tables.Add(3, 3) ' 3x3 table

		' Iterate over cells and set their content
		For i As Integer = 0 To table.Rows.Count - 1
			Dim j As Integer = 0
			Do While j < table.Rows(i).Cells.Count
				table.Rows(i).Cells(j).Paragraphs.Add().AppendText($"Cell {i+1},{j+1}")
				j += 1
			Loop
		Next i

		document.SaveAs("example_with_table.docx")
	End Sub
End Class
$vbLabelText   $csharpLabel

ライセンスとサポートの提供

IronWord は有料ライブラリです; ただし、無料の試用ライセンスはこちらで入手可能です。

Iron Softwareについての詳細は、弊社のウェブサイトをご覧ください:https://ironsoftware.com/。 サポートやお問い合わせについては、チームにお尋ねください

Iron Software からのサポート

一般的なサポートや技術のお問い合わせは、次のメールアドレスまでご連絡ください:support@ironsoftware.com

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はいいですか?
Nuget ダウンロード 25,807 | バージョン: 2025.11 ただ今リリースされました