IRONSOFTWAREHOME

How to Add Style to Text in DOCX with C#

Ahmad Sohail
Ahmad Sohail
Updated: 2026年6月4日

IronWordのTextStyleクラスは、.NET開発者がWordドキュメントにプログラムでプロフェッショナルなテキストフォーマット(フォント、色、太字、斜体、下線など)を適用することを可能にします。 レポートの作成、テンプレートの作成、文書作成の自動化など、IronWordはMicrosoft Wordの書式オプションを再現する包括的なスタイリング・ツールを提供します。

クイックスタート: C# を使用して DOCX 内のテキストにスタイルを設定する
  1. 1Install IronWord with NuGet Package Manager

    PM > Install-Package IronWord

  2. 2このコード スニペットをコピーして実行します。

    // Quick example
    using IronWord;
    using IronWord.Models;
    
    // Initialize a new Word document
    WordDocument doc = new WordDocument();
    
    // Create a Run with styled text
    Run textRun = new Run(new TextContent("Styled text"));
    
    // Apply styling properties to the Run
    textRun.Style = new TextStyle()
    {
        IsBold = true,
        Color = Color.Red,
        FontSize = 16,
        TextFont = new Font()
        {
            FontFamily = "Arial"
        }
    };
    
    // Create paragraph and add the styled Run
    Paragraph paragraph = new Paragraph();
    paragraph.AddChild(textRun);
    
    // Add paragraph to document and save
    doc.AddParagraph(paragraph);
    doc.SaveAs("styled.docx");
    C#
  3. 3実際の環境でテストするためにデプロイする

    今日プロジェクトで IronWord を使い始めましょう無料トライアル
    arrow pointer

DOCXにテキストスタイルを追加するには?

IronWordでテキストスタイルを適用するには、Runラッパーパターンを使用する必要があります。 まずRunオブジェクトを作成します。 プロパティとしてTextStyleを適用します。

スタイル適用後、Runを追加し、段落を文書に挿入して結果を保存します。 このアプローチでは、一貫したスタイルが要求される自動文書生成シナリオ向けに、テキスト書式をプログラムで制御できます。

IronWordのドキュメント階層は、DocumentDocumentSectionParagraphRunTextContentの構造に従います。 スタイルはTextContentに直接は適用されません。

using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;

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

// Configure text
Run textRun = new Run(new TextContent("Add text using IronWord"));

// Configure text style settings
textRun.Style = new TextStyle()
{
    FontSize = 24, // Text Size is 24
    TextFont = new Font()
    {
        FontFamily = "Calibri" // Text Font is "Calibri"
    },
    Color = Color.Red, // Set text color to red
    IsBold = true,     // Make text bold
    IsItalic = true,   // Make text italic
    Underline = new Underline(), // Have an underline
    Strike = StrikeValue.DoubleStrike, // Double strike-through
};

Paragraph paragraph = new Paragraph();

// Add text to paragraph
paragraph.AddChild(textRun);

// Add paragraph to document
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("add-text-style.docx");
C#

どのようなアウトプットを生成しますか?

Microsoft Wordのインターフェイスで、レイアウトリボンと赤の取り消し線付きテキスト書式が適用されたドキュメントを示す。

TextFontプロパティ内で設定されます。 TextContentをラップし、IronWordのドキュメント階層パターンに従ってスタイルを保持します。 この例はRunに適用されたとき、複数のスタイリングプロパティが組み合わさってリッチなフォーマットのテキストを作成する方法を示しています。


どのようなスタイルを追加できますか?

テキストの色を変更するにはどうすればよいですか?

IronWord.Models.Colorの事前定義された色またはカスタムの16進値を使用してテキストカラーを設定します。 特定のコンテンツを強調したり、ブランドカラーに合わせたりします。 IronWordはレッド、ブルー、グリーン、オリーブ、ネイビー、マルーンなど幅広い色をサポートしています。

using IronWord;
using IronWord.Models;

// Create document
WordDocument doc = new WordDocument();

// Add colored text
Run textRun = new Run(new TextContent("This text is olive-colored!"));
textRun.Style = new TextStyle()
{
    Color = IronWord.Models.Color.Olive // defining text to be colored olive
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("colored-text.docx");

色つきのテキストはどのように見えますか?

Microsoft Wordのオリーブ色のテキスト書式と、フォントと段落ツールを表示する"ホーム"タブのリボン

フォント ファミリーとサイズはどのように設定しますか?

TextFontプロパティでテキスト外観をカスタマイズします。 任意のインストールされたフォント名(例:"Arial""Times New Roman")をFontSizeを設定します。 これにより、視覚的な階層が確立され、さまざまなデバイスやプラットフォームでの読みやすさが保証されます。

using IronWord;
using IronWord.Models;

// Create document
WordDocument doc = new WordDocument();

// Add text with custom font family and size
Run textRun = new Run(new TextContent("This text uses Arial at 24pt!"));
textRun.Style = new TextStyle()
{
    FontSize = 24,  // Set font size in points
    TextFont = new IronWord.Models.Font()
    {
        FontFamily = "Arial"  // Set font family
    }
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("font-styled-text.docx");

カスタム フォント スタイリングはどのように見えますか?

Microsoft Wordのツールバーで選択された24ptのArialフォントと表示された書式付きサンプルテキスト

テキストを太字にするにはどうすればよいですか?

Boldにします。 Boldテキストは、見出し、強調、重要な情報のハイライトによく使用されます。 他のスタイリングプロパティと組み合わせることで、Boldテキストは視覚的な階層を作り出し、読みやすさを向上させます。

using IronWord;
using IronWord.Models;

// Create document
WordDocument doc = new WordDocument();

// Add bold text
Run textRun = new Run(new TextContent("this is bold!"));
textRun.Style = new TextStyle()
{
    IsBold = true  // Make text bold
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("bold-text.docx");

太字はどのように見えますか?

これは太字です!"テキストが文書内に表示され、太字のテキスト書式を示すMicrosoft Wordのインターフェース

テキストを斜体にするには?

trueに設定します。 Italicテキストは通常、強調、タイトル、外国語、または技術用語に使用されます。 この微妙なフォーマットにより、Boldフォーマットの視覚的な重みがなくてもテキスト要素を区別できます。

using IronWord;
using IronWord.Models;

// Create document
WordDocument doc = new WordDocument();

// Add italic text
Run textRun = new Run(new TextContent("this is italic."));
textRun.Style = new TextStyle()
{
    IsItalic = true  // Make text italic
};

Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);
doc.AddParagraph(paragraph);

// Save document
doc.SaveAs("italic-text.docx");

斜体のテキストはどのように見えますか?

ホームタブの書式設定オプションがリボンインターフェースに表示されているイタリック体のテキストを示すWord文書

利用可能なスタイリング プロパティは何ですか?

IronWordはMicrosoft Wordの書式オプションを反映した包括的なスタイル設定プロパティを提供します。 これらの特性を組み合わせて、プロフェッショナルな文書基準を満たす複雑なテキストフォーマットを作成します。

スタイリング方法翻訳内容翻訳例
テキストフォントFontオブジェクトを使用してフォント ファミリを設定し、テキストの外観をカスタマイズします。注: FontSizeFont内ではなく、 TextStyleレベルで設定されます。textRun.Style = new TextStyle() { FontSize = 24, TextFont = new Font() { FontFamily = "Calibri" } };
カラーIronWord.Models.Colorからの定義済みの色またはカスタム16進数値を使用してテキストの色を設定します。textRun.Style.Color = IronWord.Models.Color.Red;
IsBold見出しや強調によく使用されるtrueに設定するとテキストをBoldにします。textRun.Style.IsBold = true;
IsItalic強調またはタイトルに通常使用されるtrueに設定するとテキストにItalicスタイルを適用します。textRun.Style.IsItalic = true;
アンダーラインさまざまな下線スタイルを持つアンダーラインオブジェクトを使用してテキストにアンダーラインを追加します。textRun.Style.Underline = new Underline();
ストライクStrikeValue列挙を使用してストライクまたはDoubleStrikeのテキストに打ち消し線を適用します。textRun.Style.Strike = StrikeValue.Strike;
キャップテキストに大文字化効果を適用し、すべての文字を大文字表示に変換します。textRun.Style.Caps = true;
CharacterScale文字の幅を通常のサイズに対する割合で調整します。textRun.Style.CharacterScale = 150;
Embossテキストにエンボス効果を適用し、盛り上がった外観を作成します。textRun.Style.Emboss = true;
強調EmphasisMarkValues列挙値を使用して、スタイル付きテキストに強調マークを追加します。textRun.Style.Emphasis = EmphasisMarkValues.Dot;
行間行間オブジェクトを使用して、読みやすさを向上させるためにテキストの行間を制御します。textRun.Style.LineSpacing = new LineSpacing() { Value = 1.5 };
概要アウトライン効果でテキストをレンダリングし、文字の境界のみを表示します。textRun.Style.Outline = true;
シェーディングシェーディングオブジェクトを使用して、テキストに背景色やシェーディングを適用します。textRun.Style.Shading = new Shading() { Color = Color.Yellow };
スモールキャップ大文字と小文字の区別を維持しながら、小文字を小文字に変換します。textRun.Style.SmallCaps = true;
縦位置ポイント単位で、ベースラインに対するテキストの垂直方向の配置を調整します。textRun.Style.VerticalPosition = 5.0;
VerticalTextAlignmentVerticalPositionValues列挙を使用して、コンテナ内でテキストを垂直に配置します。textRun.Style.VerticalTextAlignment = VerticalPositionValues.Superscript;

複数のスタイルを組み合わせる

IronWordのテキスト・スタイリング・パワーは、複数のプロパティを組み合わせることで複雑な書式を実現します。 以下は、さまざまなスタイリングプロパティを組み合わせて、プロフェッショナルなスタイルに仕上げたテキストの例です:

using IronWord;
using IronWord.Models;

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

// Create richly formatted header text using Run
Run headerRun = new Run(new TextContent("Professional Document Header"));
headerRun.Style = new TextStyle()
{
    FontSize = 28,
    TextFont = new Font()
    {
        FontFamily = "Georgia"
    },
    Color = Color.DarkBlue,
    IsBold = true,
    SmallCaps = true,
    Underline = new Underline(),
    CharacterScale = 110,  // Slightly expand character width
    Shading = new Shading()
    {
        Color = Color.LightGray  // Light background
    }
};

// Add header to document using AddChild for styled Run
Paragraph headerParagraph = new Paragraph();
headerParagraph.AddChild(headerRun);
doc.AddParagraph(headerParagraph);

// Create body text with different styling
Run bodyRun = new Run(new TextContent("This is professionally formatted body text with custom styling."));
bodyRun.Style = new TextStyle()
{
    FontSize = 11,
    TextFont = new Font()
    {
        FontFamily = "Calibri"
    },
    Color = Color.Black
};

Paragraph bodyParagraph = new Paragraph();
bodyParagraph.AddChild(bodyRun);
doc.AddParagraph(bodyParagraph);

// Save the document
doc.SaveAs("professional-document.docx");
C#

この包括的なスタイリングアプローチにより、アプリケーションのドキュメント生成プロセス全体を通して、一貫したブランディングとプロフェッショナルな外観を維持したドキュメントが作成されます。

よくある質問

C#でプログラム的にWord文書にテキスト書式を適用するにはどうすればよいですか?

IronWordのTextStyleクラスを使用すると、フォント、色、太字、斜体、下線などのプロフェッショナルなテキスト書式を適用することができます。テキストを含むTextContentオブジェクトを作成し、必要なプロパティを持つTextStyleを適用して段落に追加し、文書を保存するだけです。

DOCXファイルのテキストをスタイル設定する基本的な手順は?

IronWordでテキストをスタイルするには: 1) NuGet経由でIronWordをインストール、2) WordDocumentオブジェクトを作成、3) テキストでTextContentを作成、4) フォント、色、太字などのTextStyleプロパティを適用、5) テキストを段落に追加して保存。

どのようなテキストフォーマットオプションがありますか?

IronWordのTextStyleクラスは、フォント・プロパティ(FontFamilyとFontSize)、テキスト・カラー、ボールド、イタリック、アンダーライン、取り消し線などの重要な書式オプションを提供します。これらのオプションを組み合わせることで、リッチな書式のテキストを作成することができます。

テキストのフォントファミリーとサイズを変更するにはどうすればよいですか?

TextStyleのTextFontプロパティを使用して、フォントファミリーとサイズを指定します。FontFamilyには「Arial」や「Times New Roman」などのフォントを設定し、FontSizeには希望のポイントサイズ(大きなテキストの場合は16など)を設定します。

複数のテキストスタイルを同時に適用できますか?

はい、IronWordでは複数のスタイリング・プロパティを一つのTextStyleオブジェクトにまとめることができます。太字、斜体、色、フォントの変更を一度に適用し、複雑なテキスト書式を作成することができます。

C# を使用して Word 文書のテキストの色を変更するにはどうすればよいですか?

IronWordのTextStyleのColorプロパティでは、IronWord.Models.Colorの定義済みの色や、カスタムの16進数値を使用してテキストの色を設定することができます。この機能により、特定のコンテンツを強調したり、ドキュメント内のブランドカラーにマッチさせることができます。

What property is used to italicize text in IronWord?

The IsItalic property is used within the TextStyle class to apply italic formatting to text in IronWord documents.

How do I apply an underline to text using IronWord?

To underline text in an IronWord document, create a new Underline object and assign it to the Underline property in the TextStyle class for the Run object containing your text.

Can I apply complex text styling using multiple properties in IronWord?

Yes, IronWord enables complex text styling by combining multiple TextStyle properties, such as FontSize, Color, IsBold, and Underline, to create richly formatted text in Word documents.

What is the benefit of using IronWord for text styling in DOCX documents?

IronWord offers programmatic control over text styling in DOCX documents, allowing developers to automate document creation while ensuring consistent and professional formatting similar to Microsoft Word.

Ahmad Sohail
フルスタックデベロッパー

Ahmadは、C#、Python、およびウェブ技術に強い基盤を持つフルスタック開発者です。彼はスケーラブルなソフトウェアソリューションの構築に深い関心を持ち、デザインと機能が実際のアプリケーションでどのように融合するかを探求することを楽しんでいます。

...
詳しく読む

準備はできましたか?

Nuget Downloads 56,401バージョン:2026.9リリースされたばかり

あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。
PDF用C# NuGetライブラリ
NuGetでインストール

バージョン: 2026.9

PM > Install-Package IronWord
nuget.org/packages/IronWord/
  1. ソリューションエクスプローラーで参照を右クリックし、NuGetパッケージを管理を選択
  2. [参照]を選択し、「IronWord」を検索してください。
  3. パッケージを選択してインストール
C# PDF DLL
DLLをダウンロード

バージョン: 2026.9

  1. IronWordをダウンロードして、ソリューションディレクトリ内の~/Libsなどの場所に解凍してください。
  2. Visual Studioのソリューションエクスプローラーで、[参照]を右クリックします。 [参照]を選択し、「IronWord.dll」を選択します。

$999からのライセンス

Key in blue circle

無料の30日間トライアルキーをすぐに入手してください。

Your trial license will be sent to your email address

制限なし。100% ロック解除済み。クレジットカード不要。

bullet_checkedクレジットカードやアカウントの作成は不要です。制限なし。100% ロック解除済み。クレジットカード不要。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
無料のライブデモを予約する
Booking Badge

世界中の数百万人のエンジニアから信頼されています。

ライセンスはより安く
義務のない相談を受ける
下記のフォームを記入するか、sales@ironsoftware.comにメールしてください。
あなたの詳細は常に守秘されます。
世界中の数百万人のエンジニアから信頼されています。
ライセンスはより安く
あなたの無料30日間の試用キーをすぐに入手。
クレジットカードやアカウントの作成は不要です。