IronWord (アイアンワード)を始める

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

アイアンワード.NET用Word文書ライブラリ

**IronWord (アイアンワード)はIron Software (アイアンソフトウェア)によって開発されたWord文書ライブラリです。 IronWord (アイアンワード)は、.NETアプリケーションでWord文書を操作するための堅牢な機能を提供することに優れています。

  • WordおよびDocxドキュメントの読み込み、操作、保存。
  • ページ設定:用紙サイズ、ページの向き、余白、背景色を設定します。
  • TextRun:テキストコンテンツ、スタイル、分割、テキストの追加、画像の追加を扱う。
  • TextStyle:フォントファミリ、サイズ、色、太字、斜体、取り消し線、下線、上付き文字、下付き文字の管理。
  • 段落:テキストラン、画像、図形の追加、スタイルの設定、整列、箇条書き、番号リストの追加。
  • 表:行の追加、セル値の取得と設定、行の削除、セルの結合など、テーブル構造の操作。
  • 画像:ファイルまたはストリームから画像を読み込み、ラップテキスト、位置オフセット、幅、高さ、およびその他のプロパティを設定します。
  • 形状:ラップテキスト、位置オフセット、幅、高さ、形状タイプ、回転の設定。

インストール

アイアンワード・ライブラリー

IronWord (アイアンワード)のインストールは簡単で、このようにパッケージをインストールしてください:

Install-Package IronWord

または IronWord NuGet公式サイト.

インストールが完了したら、C#(シーシャープ)コードの先頭にusing IronWord;を追加することで使い始めることができる。

ライセンスキーの適用

次に、ライセンスキーを License クラスの LicenseKey プロパティに代入して、有効なライセンスキーまたはトライアルキーをアイアンワードに適用する。 IronWord(アイアンワード)のメソッドを使用する前に、import文の直後に以下のコードを記述してください:

:path=/static-assets/word/content-code-examples/get-started/get-started-license.cs
IronWord.License.LicenseKey = "IRONWORD.MYLICENSE.KEY.1EF01";
IronWord.License.LicenseKey = "IRONWORD.MYLICENSE.KEY.1EF01"
VB   C#

コード例

IronWord (アイアンワード)で作成されたDOCXファイルをMicrosoft Wordの特定のバージョンで開くと、互換モードになり、スタイリングの一部が使用できなくなることがあります。 互換モードを解除してWord文書を変換するには:

  1. ファイル'> '情報'を選択し、 "変換 "をクリックします。

  2. 文書が最新のファイル形式にアップグレードされるというメッセージが表示されます。 OK "をクリックする。

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

コンストラクタを使って WordDocument クラスをインスタンス化し、Word文書を作成する。 その後、SaveAsメソッドを使用してWord文書をエクスポートします。

:path=/static-assets/word/content-code-examples/get-started/get-started-1.cs
using IronWord;
using IronWord.Models;

// Create textrun
Text textRun = new Text("Sample text");

Paragraph paragraph = new Paragraph();
paragraph.AddText(textRun);

// Create a new Word document
WordDocument doc = new WordDocument(paragraph);

// Export docx
doc.SaveAs("document.docx");
Imports IronWord
Imports IronWord.Models

' Create textrun
Private textRun As New Text("Sample text")

Private paragraph As New Paragraph()
paragraph.AddText(textRun)

' Create a new Word document
Dim doc As New WordDocument(paragraph)

' Export docx
doc.SaveAs("document.docx")
VB   C#

画像を追加

画像は単独では追加できない; その代わりに、 ParagraphTableCellSectionなどの文書構造のいずれかに追加する必要がある。 画像を追加するには AddImage メソッドを使う。

:path=/static-assets/word/content-code-examples/get-started/get-started-2.cs
using IronWord;
using IronWord.Models;

// Load docx
WordDocument doc = new WordDocument("document.docx");

// Configure image
IronWord.Models.Image image = new IronWord.Models.Image("image.jpg");
image.Width = 250; // In unit pixel
image.Height = 200; // In unit pixel
Paragraph paragraph = new Paragraph();

// Add image
paragraph.AddImage(image);

// Add paragraph
doc.AddParagraph(paragraph);

// Export docx
doc.SaveAs("save_document.docx");
Imports IronWord
Imports IronWord.Models

' Load docx
Private doc As New WordDocument("document.docx")

' Configure image
Private image As New IronWord.Models.Image("image.jpg")
image.Width = 250 ' In unit pixel
image.Height = 200 ' In unit pixel
Dim paragraph As New Paragraph()

' Add image
paragraph.AddImage(image)

' Add paragraph
doc.AddParagraph(paragraph)

' Export docx
doc.SaveAs("save_document.docx")
VB   C#

テーブルを追加

表を追加するには、表、行、列、表のセルを作成しなければならないので、もう少し手間がかかる。 しかし、このセットアップの場合、コンフィギュレーションに大きなチャンスがある。 各セルは異なるスタイルを持つことができる。 様々なボーダー・スタイル、24種類の豊富なセレクションをご覧ください。

:path=/static-assets/word/content-code-examples/get-started/get-started-3.cs
using IronWord;
using IronWord.Models;

// Create table cell
TableCell cell = new TableCell();

Text textRun = new Text();
textRun.Text = "Sample text";

// Add textrun to the cell
cell.AddChild(new Paragraph(textRun));

// Configure border style
BorderStyle borderStyle = new BorderStyle();
borderStyle.BorderColor = Color.Black;
borderStyle.BorderValue = IronWord.Models.Enums.BorderValues.Thick;
borderStyle.BorderSize = 5;

// Configure table border
TableBorders tableBorders = new TableBorders() {
    TopBorder = borderStyle,
    RightBorder = borderStyle,
    BottomBorder = borderStyle,
    LeftBorder = borderStyle,
};

cell.Borders = tableBorders;

// Create row and add cell
TableRow row = new TableRow();
row.AddCell(cell);
row.AddCell(cell);

// Create table and add row
Table table = new Table();
table.AddRow(row);

// Create new Word document from the table
WordDocument doc = new WordDocument(table);

// Export Word document
doc.SaveAs("Document.docx");
Imports IronWord
Imports IronWord.Models

' Create table cell
Private cell As New TableCell()

Private textRun As New Text()
textRun.Text = "Sample text"

' Add textrun to the cell
cell.AddChild(New Paragraph(textRun))

' Configure border style
Dim borderStyle As New BorderStyle()
borderStyle.BorderColor = Color.Black
borderStyle.BorderValue = IronWord.Models.Enums.BorderValues.Thick
borderStyle.BorderSize = 5

' Configure table border
Dim tableBorders As New TableBorders() With {
	.TopBorder = borderStyle,
	.RightBorder = borderStyle,
	.BottomBorder = borderStyle,
	.LeftBorder = borderStyle
}

cell.Borders = tableBorders

' Create row and add cell
Dim row As New TableRow()
row.AddCell(cell)
row.AddCell(cell)

' Create table and add row
Dim table As New Table()
table.AddRow(row)

' Create new Word document from the table
Dim doc As New WordDocument(table)

' Export Word document
doc.SaveAs("Document.docx")
VB   C#

ライセンスおよびサポート利用可能

アイアンワードは有料ライブラリですが、無料のトライアルライセンスもあります。 これ.

Iron Software (アイアン・ソフトウェア)の詳細については、当社のウェブサイトをご覧ください:https://ironsoftware.com/ その他のサポートやお問い合わせは下記までお願いいたします。 私たちのチームにお問い合わせください.

アイアンソフトウェアのサポート

一般的なサポートや技術的なお問い合わせは、電子メールでご連絡ください:support@ironsoftware.com