
.NET Word API (How It Works For Developers)
.NET Word APIは、開発者にWord文書を変換し、操作するための強力なツールを提供します。 このAPIは、Microsoft Wordドキュメントを扱うプロセスを簡素化するように設計されており、プログラムによってドキュメントを作成、編集、変換、管理することが容易になります。 この記事では、IronWordの機能を探求し、Word文書を操作する方法を理解します。
IronWordの紹介
IronWordは、.NET Word APIエコシステム内 for .NET Wordライブラリで、.NETアプリケーション内でMicrosoft Word文書を処理するために特別に設計されています。 IronWordを使用すると、開発者はサーバーまたはクライアントマシンにMicrosoft Wordをインストールする必要なく、Wordドキュメントを簡単に読み書きおよび修正できます。 この機能は、報告書、請求書、郵便物結合機能を通じたパーソナライズされた通信など、ドキュメントプロセスの自動化が必要なアプリケーションに特に有益です。
IronWordの機能
IronWordは、Wordドキュメント操作のさまざまな側面に対応する包括的な機能を提供します。 各機能セットを探求し、それらがどのように複数のドキュメントの操作と結合を可能にするかを、"ドキュメント構造"と"ドキュメント要素"に分類して説明します。
ドキュメント構造
Word文書の閲覧と編集: IronWordを使えば、Word文書から特定の情報を抽出できます。例えば、編集や再利用のためにテキストを抽出したり、他の場所で使用する必要がある画像を取得したりできます。 この機能は、Wordドキュメントを結合し、既存のDOCXファイルに含まれる情報を処理することを目的としたアプリケーションにとって重要です。
複数のフォーマットに対応: IronWordは幅広いファイルフォーマットをサポートしており、 .NETアプリケーション内でWord文書を変換する際の利便性を高めています。
ページ設定の編集: IronWordを使用すると、Word 文書の物理的なレイアウトを簡単にカスタマイズできます。 さまざまなMS Wordファイルの用紙サイズを標準またはカスタムの寸法に調整し、ドキュメントの異なるセクションの向きを変更し、適切な整列を確保するためにマージンを設定し、また美観を考慮してセクションを強調するために背景色を変更することができます。
段落の追加: IronWord、段落内のテキストの追加と削除が可能で、これは大量のテキストを編集および書式設定する際に不可欠です。 さらに、画像や図形を直接テキストに挿入して段落を向上させ、デザイン仕様に合わせてスタイルを調整し、洗練された外観のために配置を設定することができます。 項目符号や番号付きリストの追加も、より効果的にコンテンツを整理するのに役立ちます。
using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
// Load docx
WordDocument doc = new WordDocument();
// Create and add styled text to a paragraph
Paragraph paragraph = new Paragraph();
// Adding regular text
paragraph.AddTextRun(new TextRun("Exploring text styles within a document."));
// Adding italic text
paragraph.AddTextRun(new TextRun("An example in italic.", new TextStyle { IsItalic = true }));
// Adding bold text
paragraph.AddTextRun(new TextRun("An example in bold.", new TextStyle { IsBold = true }));
// Add paragraph to the document and export docx
doc.AddParagraph(paragraph);
doc.SaveAs("newdocument.docx");
}
}Imports IronWord
Imports IronWord.Models
Module Program
Sub Main()
' Load docx
Dim doc As New WordDocument()
' Create and add styled text to a paragraph
Dim paragraph As New Paragraph()
' Adding regular text
paragraph.AddTextRun(New TextRun("Exploring text styles within a document."))
' Adding italic text
paragraph.AddTextRun(New TextRun("An example in italic.", New TextStyle With {.IsItalic = True}))
' Adding bold text
paragraph.AddTextRun(New TextRun("An example in bold.", New TextStyle With {.IsBold = True}))
' Add paragraph to the document and export docx
doc.AddParagraph(paragraph)
doc.SaveAs("newdocument.docx")
End Sub
End ModuleImports IronWord
Imports IronWord.Models
Module Program
Sub Main()
' Load docx
Dim doc As New WordDocument()
' Create and add styled text to a paragraph
Dim paragraph As New Paragraph()
' Adding regular text
paragraph.AddTextRun(New TextRun("Exploring text styles within a document."))
' Adding italic text
paragraph.AddTextRun(New TextRun("An example in italic.", New TextStyle With {.IsItalic = True}))
' Adding bold text
paragraph.AddTextRun(New TextRun("An example in bold.", New TextStyle With {.IsBold = True}))
' Add paragraph to the document and export docx
doc.AddParagraph(paragraph)
doc.SaveAs("newdocument.docx")
End Sub
End Module表の追加:表はDOCXファイルの重要な構成要素であり、 IronWordで簡単に操作でき、動的なドキュメント生成をサポートします。 行と列の追加や削除が可能であり、データ量が変動する動的なドキュメント生成において重要な操作です。 セルの結合および分割により、複雑なテーブルをフォーマットする柔軟性を提供し、境界線やレイアウト寸法をカスタマイズすることで、洗練されたプロフェッショナルな外観を実現します。
using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
// Create a table cell with a paragraph containing text
TableCell cell = new TableCell(new Paragraph(new TextRun("Sample text")));
// Configure a common border style for the table
BorderStyle borderStyle = new BorderStyle
{
BorderColor = new IronColor(IronSoftware.Drawing.Color.Black),
BorderValue = IronWord.Models.Enums.BorderValues.Thick,
BorderSize = 5
};
// Apply the border style to the cell
cell.Borders = new TableBorders
{
TopBorder = borderStyle,
RightBorder = borderStyle,
BottomBorder = borderStyle,
LeftBorder = borderStyle
};
// Create a table row and add the same cell twice
TableRow row = new TableRow();
row.AddCell(cell);
row.AddCell(cell);
// Create a table, add the row, then create and export the Word document
Table table = new Table();
table.AddRow(row);
WordDocument doc = new WordDocument(table);
doc.SaveAs("Document.docx");
}
}using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
// Create a table cell with a paragraph containing text
TableCell cell = new TableCell(new Paragraph(new TextRun("Sample text")));
// Configure a common border style for the table
BorderStyle borderStyle = new BorderStyle
{
BorderColor = new IronColor(IronSoftware.Drawing.Color.Black),
BorderValue = IronWord.Models.Enums.BorderValues.Thick,
BorderSize = 5
};
// Apply the border style to the cell
cell.Borders = new TableBorders
{
TopBorder = borderStyle,
RightBorder = borderStyle,
BottomBorder = borderStyle,
LeftBorder = borderStyle
};
// Create a table row and add the same cell twice
TableRow row = new TableRow();
row.AddCell(cell);
row.AddCell(cell);
// Create a table, add the row, then create and export the Word document
Table table = new Table();
table.AddRow(row);
WordDocument doc = new WordDocument(table);
doc.SaveAs("Document.docx");
}
}Imports IronWord
Imports IronWord.Models
Module Program
Sub Main()
' Create a table cell with a paragraph containing text
Dim cell As New TableCell(New Paragraph(New TextRun("Sample text")))
' Configure a common border style for the table
Dim borderStyle As New BorderStyle With {
.BorderColor = New IronColor(IronSoftware.Drawing.Color.Black),
.BorderValue = IronWord.Models.Enums.BorderValues.Thick,
.BorderSize = 5
}
' Apply the border style to the cell
cell.Borders = New TableBorders With {
.TopBorder = borderStyle,
.RightBorder = borderStyle,
.BottomBorder = borderStyle,
.LeftBorder = borderStyle
}
' Create a table row and add the same cell twice
Dim row As New TableRow()
row.AddCell(cell)
row.AddCell(cell)
' Create a table, add the row, then create and export the Word document
Dim table As New Table()
table.AddRow(row)
Dim doc As New WordDocument(table)
doc.SaveAs("Document.docx")
End Sub
End ModuleImports IronWord
Imports IronWord.Models
Module Program
Sub Main()
' Create a table cell with a paragraph containing text
Dim cell As New TableCell(New Paragraph(New TextRun("Sample text")))
' Configure a common border style for the table
Dim borderStyle As New BorderStyle With {
.BorderColor = New IronColor(IronSoftware.Drawing.Color.Black),
.BorderValue = IronWord.Models.Enums.BorderValues.Thick,
.BorderSize = 5
}
' Apply the border style to the cell
cell.Borders = New TableBorders With {
.TopBorder = borderStyle,
.RightBorder = borderStyle,
.BottomBorder = borderStyle,
.LeftBorder = borderStyle
}
' Create a table row and add the same cell twice
Dim row As New TableRow()
row.AddCell(cell)
row.AddCell(cell)
' Create a table, add the row, then create and export the Word document
Dim table As New Table()
table.AddRow(row)
Dim doc As New WordDocument(table)
doc.SaveAs("Document.docx")
End Sub
End Module
ドキュメント要素
TextRunsを追加する:この機能は、テキストコンテンツをきめ細かく制御することに重点を置いています。 テキストを追加、付加、分割することができ、これは動的なドキュメント作成に不可欠です。 スタイルオプションは豊富で、フォントファミリー、サイズ、色の変更、太字、イタリックなどのテキスト装飾の追加が含まれます。 テキストランに画像を埋め込むこともでき、リッチで視覚的に魅力的なドキュメントを作成します。
画像の追加: IronWord、Word文書内で包括的な画像操作が可能です。 さまざまなソースから画像をロードし、それらの周りにスムーズにテキストを配置し、レイアウトに合わせて寸法を調整することができます。 位置オフセットを設定し、ドキュメントのコーナーからの距離を設定することで、常に完璧に配置されます。
using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
WordDocument doc = new WordDocument();
// Load and configure the image
IronWord.Models.Image image = new IronWord.Models.Image("your-image.jpg")
{
Width = 200, // In unit pixels
Height = 200 // In unit pixels
};
// Create paragraph, add image, add paragraph to document, and export
Paragraph paragraph = new Paragraph();
paragraph.AddImage(image);
// Add paragraph containing the image to the document
doc.AddParagraph(paragraph);
doc.SaveAs("save_document.docx");
}
}using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
WordDocument doc = new WordDocument();
// Load and configure the image
IronWord.Models.Image image = new IronWord.Models.Image("your-image.jpg")
{
Width = 200, // In unit pixels
Height = 200 // In unit pixels
};
// Create paragraph, add image, add paragraph to document, and export
Paragraph paragraph = new Paragraph();
paragraph.AddImage(image);
// Add paragraph containing the image to the document
doc.AddParagraph(paragraph);
doc.SaveAs("save_document.docx");
}
}Imports IronWord
Imports IronWord.Models
Module Program
Sub Main()
Dim doc As New WordDocument()
' Load and configure the image
Dim image As New IronWord.Models.Image("your-image.jpg") With {
.Width = 200, ' In unit pixels
.Height = 200 ' In unit pixels
}
' Create paragraph, add image, add paragraph to document, and export
Dim paragraph As New Paragraph()
paragraph.AddImage(image)
' Add paragraph containing the image to the document
doc.AddParagraph(paragraph)
doc.SaveAs("save_document.docx")
End Sub
End ModuleImports IronWord
Imports IronWord.Models
Module Program
Sub Main()
Dim doc As New WordDocument()
' Load and configure the image
Dim image As New IronWord.Models.Image("your-image.jpg") With {
.Width = 200, ' In unit pixels
.Height = 200 ' In unit pixels
}
' Create paragraph, add image, add paragraph to document, and export
Dim paragraph As New Paragraph()
paragraph.AddImage(image)
' Add paragraph containing the image to the document
doc.AddParagraph(paragraph)
doc.SaveAs("save_document.docx")
End Sub
End Module図形を追加する:図形は文書に大きな視覚的インパクトを与えることができ、 IronWordにはそれらを正確に挿入およびカスタマイズするためのツールが用意されています。 長方形、円、矢印などの図形タイプを設定し、図形周りのテキストの配置方法を決定し、正確な寸法と位置を指定し、望ましい視覚的効果を得るために図形を回転させることもできます。
互換性
.NETバージョンとプロジェクトタイプ

IronWordは、.NETエコシステムでの幅広い互換性を念頭に設計されており、.NET Core、.NET Standard、.NET Frameworkを含むさまざまな.NETバージョンでC#、VB.NET、F#をサポートします。 これにより、最新のアプリケーションおよびレガシーアプリケーションの両方での有用性が保障されます。 ライブラリの多用途性は、Blazor、WebForms、Xamarin、MAUI、WPF、コンソールアプリケーションとの統合を介して、ウェブ、モバイル、デスクトップアプリケーションをサポートします。
アプリケーション環境

アプリケーション環境の観点から、IronWordはWindows、Linux、iOS、Androidプラットフォームに適応でき、Docker、Azure、AWSでのコンテナ化およびクラウド展開の特定のサポートも含まれています。 この広範なサポートにより、さまざまな環境での開発が容易になります。
OSとIDE

IronWordはMicrosoft Visual Studio、ReSharper、Riderなどの主要な統合開発環境(IDE)と互換性があり、開発者にツールの柔軟な選択肢を提供します。 最終的に、さまざまなオペレーティングシステムおよびプロセッサアーキテクチャ(x64、x86、ARM)をサポートし、多様なハードウェア構成での効率的なパフォーマンスを保証します。
ライセンスオプション
IronWordは、異なる開発者および組織のニーズに対応するさまざまなライセンスオプションを提供します。 彼らは一度の支払いで再発料金のない永続ライセンスを提供しています。 すべてのライセンスには1年間の製品サポートと更新が含まれています。 ライセンスタイアは、開発者の数、場所、およびプロジェクトに基づいて設計されています。 ライセンスを購入する前に、無料トライアルを取得して、実際に体験することもできます。
Liteライセンス
このオプションは、プロジェクトで一人で働く個別の開発者向けに調整されています。 $999で価格設定され、単一の場所にいる1人の開発者をカバーします。
Plusライセンス
小規模チームを対象としており、$1,499のこのライセンスは最大3人の開発者を収容し、3つのプロジェクトで3か所での使用に適用されます。
Professionalライセンス
より大規模なチーム向けに、Professionalライセンスは$2,999で販売され、最大10人の開発者をサポートします。 より大規模な運用を対象として設計されており、プレミアムサポート機能を含んでいます。
結論
まとめると、IronWordは、個々の開発者やチームの多様なニーズを満たすために、さまざまなライセンスオプションを提供する堅牢で柔軟な.NET Word APIとして浮かび上がります。 その機能は、複数 for .NETバージョンおよびプロジェクトタイプにわたる互換性を保証し、Wordドキュメントの効率的な管理と操作を可能にします。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
関連する記事
