IronWordを使い始める
IronWord: .NET のための Word ドキュメント ライブラリ
IronWord は Iron Software によって開発された Word ドキュメント ライブラリです。 IronWord は .NET アプリケーションで Word ドキュメントを扱うための強力な機能を提供します。
- Word および Docx ドキュメントの読み込み、操作、保存。
PageSetup:用紙サイズ、ページの向き、余白、背景色を設定する。TextRun:テキストコンテンツ、スタイル、分割、テキストの追加、および画像の追加を扱う。TextStyle:フォントファミリー、サイズ、色、太字、斜体、取り消し線、下線、上付き文字、下付き文字を管理する。Paragraph:テキストの流れ、画像、図形の追加、スタイルの設定、整列、箇条書き、番号付きリストを設定する。Table:テーブル構造の操作、行の追加、セルの値の取得と設定、行の削除、セルの結合などを含む。Image:ファイルやストリームから画像をロードし、テキストの折り返し、位置のオフセット、幅、高さ、およびその他のプロパティを設定する。Shape:テキストの折り返し、位置のオフセット、幅、高さ、形状タイプ、回転を設定する。
.NET 用 Word 文書 C# ライブラリ
- DOCXドキュメントを処理するためのC#ライブラリをダウンロード
- Word および DOCX ドキュメントの作成と変更
- 段落、セクション、表などの文書構造を追加する
- テキスト、画像、図形などのドキュメント要素を追加する
- ドキュメント要素を簡単にスタイル設定
インストール
IronWord ライブラリ
IronWordのインストールは迅速かつ簡単です。 次のコマンドを使用して NuGet からパッケージをインストールできます。
または、公式のIronWord NuGetウェブサイトから直接ダウンロードできます。
インストール後、C#コードファイルの上部にusing IronWord;を追加することで開始できます。
ライセンスキーの適用
次に、ライセンスキーをLicenseクラスのLicenseKeyプロパティに割り当てることによって、IronWordに有効なライセンスまたはトライアルキーを適用します。 インポート文の直後、任意の IronWord メソッドを使用する前に、次のコードを含めてください。
using IronWord;
// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";Imports IronWord
' Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"Imports IronWord
' Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"コード例
いくつかのコード例と利用可能な機能を見てみましょう。
- 「ファイル」 > 「情報」を選択し、「変換」をクリックします。
- ドキュメントが最新のファイル形式にアップグレードされるというメッセージが表示されます。 「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 ClassImports 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画像の追加
画像はそれ自体では追加できません; 代わりに、Paragraph、TableCell、またはSectionなどのドキュメント構造の一部に追加する必要があります。 AddImageメソッドを使用して画像を追加します。 例:
using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
// Add an image to a paragraph
var paragraph = new Paragraph();
section.AddParagraph(paragraph);
paragraph.AddImage(new ImageContent("path/to/image.jpg") { Width = 100, Height = 100 });
document.SaveAs("example_with_image.docx");
}
}using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
// Add an image to a paragraph
var paragraph = new Paragraph();
section.AddParagraph(paragraph);
paragraph.AddImage(new ImageContent("path/to/image.jpg") { Width = 100, Height = 100 });
document.SaveAs("example_with_image.docx");
}
}Imports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = New DocumentSection()
document.AddSection(section)
' Add an image to a paragraph
Dim paragraph = New Paragraph()
section.AddParagraph(paragraph)
paragraph.AddImage(New ImageContent("path/to/image.jpg") With {.Width = 100, .Height = 100})
document.SaveAs("example_with_image.docx")
End Sub
End ClassImports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = New DocumentSection()
document.AddSection(section)
' Add an image to a paragraph
Dim paragraph = New Paragraph()
section.AddParagraph(paragraph)
paragraph.AddImage(New ImageContent("path/to/image.jpg") With {.Width = 100, .Height = 100})
document.SaveAs("example_with_image.docx")
End Sub
End Class表の追加
表を追加するには、表、行、列、および表セルの作成が必要です。 これにより、各セルに異なるスタイルを持たせることができるため、重要な構成の機会が得られます。 例:
using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
var table = new Table(3, 3); // 3x3 table
section.AddTable(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++)
{
((TableCell)table.Rows[i].Cells[j]).AddParagraph(new Paragraph(new TextContent($"Cell {i+1},{j+1}")));
}
}
document.SaveAs("example_with_table.docx");
}
}using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
var table = new Table(3, 3); // 3x3 table
section.AddTable(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++)
{
((TableCell)table.Rows[i].Cells[j]).AddParagraph(new Paragraph(new TextContent($"Cell {i+1},{j+1}")));
}
}
document.SaveAs("example_with_table.docx");
}
}Imports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document As New WordDocument()
Dim section As New DocumentSection()
document.AddSection(section)
Dim table As New Table(3, 3) ' 3x3 table
section.AddTable(table)
' Iterate over cells and set their content
For i As Integer = 0 To table.Rows.Count - 1
For j As Integer = 0 To table.Rows(i).Cells.Count - 1
CType(table.Rows(i).Cells(j), TableCell).AddParagraph(New Paragraph(New TextContent($"Cell {i + 1},{j + 1}")))
Next
Next
document.SaveAs("example_with_table.docx")
End Sub
End ClassImports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document As New WordDocument()
Dim section As New DocumentSection()
document.AddSection(section)
Dim table As New Table(3, 3) ' 3x3 table
section.AddTable(table)
' Iterate over cells and set their content
For i As Integer = 0 To table.Rows.Count - 1
For j As Integer = 0 To table.Rows(i).Cells.Count - 1
CType(table.Rows(i).Cells(j), TableCell).AddParagraph(New Paragraph(New TextContent($"Cell {i + 1},{j + 1}")))
Next
Next
document.SaveAs("example_with_table.docx")
End Sub
End Classライセンスとサポートの提供
IronWord は有料ライブラリです; ただし、無料のトライアルライセンスはこちらで利用可能です。
Iron Softwareに関する詳細情報は、こちらのウェブサイトをご覧ください:https://ironsoftware.com/。 さらなるサポートやお問い合わせについては、当社のチームにお尋ねください。
Iron Software からのサポート
一般的なサポートや技術的なお問い合わせは、support@ironsoftware.com までメールでお送りください。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。