C#でDOCXのテキストにスタイルを追加する方法
IronWordのTextStyleクラスを使うと、.NET開発者は、Word文書のフォント、色、太字、斜体、下線などの書式をプログラムで設定できます。IronWordにはMicrosoft Wordの書式設定に相当する機能がそろっており、レポートやテンプレートの作成、文書生成の自動化に利用できます。
-
1IronWord を NuGet Package Manager でインストールします
-
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");Imports IronWord Imports IronWord.Models ' Initialize a new Word document Dim doc As New WordDocument() ' Create a Run with styled text Dim textRun As New Run(New TextContent("Styled text")) ' Apply styling properties to the Run textRun.Style = New TextStyle() With { .IsBold = True, .Color = Color.Red, .FontSize = 16, .TextFont = New Font() With { .FontFamily = "Arial" } } ' Create paragraph and add the styled Run Dim paragraph As New Paragraph() paragraph.AddChild(textRun) ' Add paragraph to document and save doc.AddParagraph(paragraph) doc.SaveAs("styled.docx")Imports IronWord Imports IronWord.Models ' Initialize a new Word document Dim doc As New WordDocument() ' Create a Run with styled text Dim textRun As New Run(New TextContent("Styled text")) ' Apply styling properties to the Run textRun.Style = New TextStyle() With { .IsBold = True, .Color = Color.Red, .FontSize = 16, .TextFont = New Font() With { .FontFamily = "Arial" } } ' Create paragraph and add the styled Run Dim paragraph As New Paragraph() paragraph.AddChild(textRun) ' Add paragraph to document and save doc.AddParagraph(paragraph) doc.SaveAs("styled.docx") -
3実際の環境でテストするためにデプロイする
今日からご自身のプロジェクトでIronWordを使い始めるには、無料トライアルをお試しください。
最小限のワークフロー(5ステップ)
- IronWord C#ライブラリをインストールする
TextContentを含むRunオブジェクトを作成するFontSize、IsBold、Colorなどのプロパティを設定したTextStyleをRunに適用するAddChildを使用してParagraphにスタイル付きRunを追加する- スタイルを適用した文書を保存する
DOCXのテキストへの書式設定
IronWordでテキストの書式を設定するには、Runでテキストをラップします。まずWordDocumentオブジェクトを作成し、続いてテキストを格納したTextContentを含むRunオブジェクトを作成します。IsBold、Color、FontSizeなどを指定したTextStyleは、TextContentではなくRunに適用します。
書式を設定したら、AddChildを使ってRunをParagraphに追加し、その段落を文書に挿入して保存します。書式をプログラムで制御できるため、自動生成する文書の書式を統一できます。
Document → (オプションのDocumentSection) → Paragraph → Run → TextContent。 段落はこのページの例で示されているように、明示的なDocumentSectionなしでWordDocumentにAddParagraphを通じて直接追加できます。 スタイルはRun レベルで適用され、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");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");Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Load docx
Dim doc As New WordDocument("sample.docx")
' Configure text
Dim textRun As New Run(New TextContent("Add text using IronWord"))
' Configure text style settings
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Text Size is 24
.TextFont = New Font() With {
.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
}
Dim paragraph As New Paragraph()
' Add text to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("add-text-style.docx")Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Load docx
Dim doc As New WordDocument("sample.docx")
' Configure text
Dim textRun As New Run(New TextContent("Add text using IronWord"))
' Configure text style settings
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Text Size is 24
.TextFont = New Font() With {
.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
}
Dim paragraph As New Paragraph()
' Add text to paragraph
paragraph.AddChild(textRun)
' Add paragraph to document
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("add-text-style.docx")出力例

TextStyleクラスでは、フォント、テキストの色、太字、斜体、下線など、基本的な書式を指定できます。FontSizeはFontの内部ではなくTextStyleで指定し、FontFamilyはTextFontプロパティ内で設定します。IronWordの文書階層では、RunオブジェクトがTextContentを内包し、書式を保持します。この例では、Runに複数の書式プロパティを組み合わせて適用しています。
設定できる書式
テキストの色をどのように変更しますか?
TextStyleのColorプロパティでは、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");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");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add colored text
Dim textRun As New Run(New TextContent("This text is olive-colored!"))
textRun.Style = New TextStyle() With {
.Color = IronWord.Models.Color.Olive ' defining text to be colored olive
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("colored-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add colored text
Dim textRun As New Run(New TextContent("This text is olive-colored!"))
textRun.Style = New TextStyle() With {
.Color = IronWord.Models.Color.Olive ' defining text to be colored olive
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("colored-text.docx")テキストに色を付けた例

フォントファミリーとサイズをどのように設定しますか?
TextFontプロパティでテキストの外観を調整します。FontFamilyにはインストール済みのフォント名(「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");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");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add text with custom font family and size
Dim textRun As New Run(New TextContent("This text uses Arial at 24pt!"))
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Set font size in points
.TextFont = New IronWord.Models.Font() With {
.FontFamily = "Arial" ' Set font family
}
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("font-styled-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add text with custom font family and size
Dim textRun As New Run(New TextContent("This text uses Arial at 24pt!"))
textRun.Style = New TextStyle() With {
.FontSize = 24, ' Set font size in points
.TextFont = New IronWord.Models.Font() With {
.FontFamily = "Arial" ' Set font family
}
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("font-styled-text.docx")フォントの設定例

テキストを太字にするにはどうしますか?
IsBoldプロパティをtrueに設定すると、テキストが太字(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");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");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add bold text
Dim textRun As New Run(New TextContent("this is bold!"))
textRun.Style = New TextStyle() With {
.IsBold = True ' Make text bold
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("bold-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add bold text
Dim textRun As New Run(New TextContent("this is bold!"))
textRun.Style = New TextStyle() With {
.IsBold = True ' Make text bold
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("bold-text.docx")太字テキストはどのように見えますか?

テキストを斜体にする方法
IsItalicプロパティをtrueに設定すると、テキストが斜体(Italic)になります。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");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");Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add italic text
Dim textRun As New Run(New TextContent("this is italic."))
textRun.Style = New TextStyle() With {
.IsItalic = True ' Make text italic
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("italic-text.docx")Imports IronWord
Imports IronWord.Models
' Create document
Dim doc As New WordDocument()
' Add italic text
Dim textRun As New Run(New TextContent("this is italic."))
textRun.Style = New TextStyle() With {
.IsItalic = True ' Make text italic
}
Dim paragraph As New Paragraph()
paragraph.AddChild(textRun)
doc.AddParagraph(paragraph)
' Save document
doc.SaveAs("italic-text.docx")斜体の表示例

書式設定のプロパティ一覧
IronWordには、Microsoft Wordの書式設定に相当するプロパティがそろっています。これらを組み合わせると、体裁を整えた文書に必要な複雑な書式も設定できます。
| 書式設定プロパティ | 説明 | 例 |
|---|---|---|
TextFont | Fontオブジェクトを使用してフォント ファミリを設定し、テキストの外観をカスタマイズします。注: FontSizeはFont内ではなく、 TextStyleレベルで設定されます。 | textRun.Style = new TextStyle() { FontSize = 24, TextFont = new Font() { FontFamily = "Calibri" } }; |
Color | 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; |
Underline | さまざまな下線スタイルを持つUnderlineオブジェクトを使用してテキストにUnderlineを追加します。 | textRun.Style.Underline = new Underline(); |
Strike | StrikeValue列挙型のStrikeまたはDoubleStrikeを指定して、テキストに一重または二重の取り消し線を引きます。 | textRun.Style.Strike = StrikeValue.Strike; |
Caps | テキストに大文字化効果を適用し、すべての文字を大文字表示に変換します。 | textRun.Style.Caps = true; |
CharacterScale | 文字の幅を通常のサイズに対する割合で調整します。 | textRun.Style.CharacterScale = 150; |
Emboss | テキストにエンボス効果を適用し、盛り上がった外観を作成します。 | textRun.Style.Emboss = true; |
Emphasis | EmphasisMarkValues列挙型の値を使って、書式を設定したテキストに圏点を付けます。 | textRun.Style.Emphasis = EmphasisMarkValues.Dot; |
LineSpacing | LineSpacingオブジェクトで行間を調整し、テキストを読みやすくします。Valueは行の高さに対する倍率です。 | textRun.Style.LineSpacing = new LineSpacing() { Value = 1.5 }; |
Outline | アウトライン効果でテキストをレンダリングし、文字の境界のみを表示します。 | textRun.Style.Outline = true; |
Shading | Shading オブジェクトを使用して、テキストに背景色やシェーディングを適用します。 | textRun.Style.Shading = new Shading() { Color = Color.Yellow }; |
SmallCaps | 大文字と小文字の区別を保ったまま、小文字を小型大文字で表示します。 | textRun.Style.SmallCaps = true; |
VerticalPosition | ポイント単位で、ベースラインに対するテキストの垂直方向の配置を調整します。 | textRun.Style.VerticalPosition = 5.0; |
VerticalTextAlignment | VerticalPositionValues列挙型を使って、コンテナー内でのテキストの垂直位置を指定します。 | 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");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");Imports IronWord
Imports IronWord.Models
' Create a new document
Dim doc As New WordDocument()
' Create richly formatted header text using Run
Dim headerRun As New Run(New TextContent("Professional Document Header"))
headerRun.Style = New TextStyle() With {
.FontSize = 28,
.TextFont = New Font() With {
.FontFamily = "Georgia"
},
.Color = Color.DarkBlue,
.IsBold = True,
.SmallCaps = True,
.Underline = New Underline(),
.CharacterScale = 110, ' Slightly expand character width
.Shading = New Shading() With {
.Color = Color.LightGray ' Light background
}
}
' Add header to document using AddChild for styled Run
Dim headerParagraph As New Paragraph()
headerParagraph.AddChild(headerRun)
doc.AddParagraph(headerParagraph)
' Create body text with different styling
Dim bodyRun As New Run(New TextContent("This is professionally formatted body text with custom styling."))
bodyRun.Style = New TextStyle() With {
.FontSize = 11,
.TextFont = New Font() With {
.FontFamily = "Calibri"
},
.Color = Color.Black
}
Dim bodyParagraph As New Paragraph()
bodyParagraph.AddChild(bodyRun)
doc.AddParagraph(bodyParagraph)
' Save the document
doc.SaveAs("professional-document.docx")Imports IronWord
Imports IronWord.Models
' Create a new document
Dim doc As New WordDocument()
' Create richly formatted header text using Run
Dim headerRun As New Run(New TextContent("Professional Document Header"))
headerRun.Style = New TextStyle() With {
.FontSize = 28,
.TextFont = New Font() With {
.FontFamily = "Georgia"
},
.Color = Color.DarkBlue,
.IsBold = True,
.SmallCaps = True,
.Underline = New Underline(),
.CharacterScale = 110, ' Slightly expand character width
.Shading = New Shading() With {
.Color = Color.LightGray ' Light background
}
}
' Add header to document using AddChild for styled Run
Dim headerParagraph As New Paragraph()
headerParagraph.AddChild(headerRun)
doc.AddParagraph(headerParagraph)
' Create body text with different styling
Dim bodyRun As New Run(New TextContent("This is professionally formatted body text with custom styling."))
bodyRun.Style = New TextStyle() With {
.FontSize = 11,
.TextFont = New Font() With {
.FontFamily = "Calibri"
},
.Color = Color.Black
}
Dim bodyParagraph As New Paragraph()
bodyParagraph.AddChild(bodyRun)
doc.AddParagraph(bodyParagraph)
' Save the document
doc.SaveAs("professional-document.docx")この方法を使うと、アプリケーションが生成する文書全体でブランドの表現を統一し、体裁を整えられます。
よくある質問
C#を使用してDOCXファイルでテキストをスタイルするにはどうすればよいですか?
IronWordライブラリを使用して、TextContentを含むRunオブジェクトを作成し、RunにTextStyleを適用することでDOCXファイルのテキストをスタイリングすることができます。TextStyleのプロパティであるFontSize、Color、IsBoldを使用すると、プログラム的にテキストの外観をカスタマイズできます。
IronWordでTextStyleクラスは何に使用されますか?
IronWordのTextStyleクラスは、Word文書内のテキストにフォント、色、太字、イタリック、下線など、さまざまなテキストフォーマットオプションを適用するために使用されます。
IronWordを使用してテキストのフォントカラーを変更するにはどうすればよいですか?
IronWordを使ってテキストのフォントカラーを変更するには、TextStyleクラスのColorプロパティを使用して、IronWord.Models.Colorの定義済みの色や特定のカラー要件のためのカスタム16進値をセットします。
IronWordでフォントファミリーとサイズの両方を設定できますか?
はい、IronWordではテキストのフォントファミリーとサイズの両方を設定できます。TextFontプロパティを使ってFontFamilyを指定し、TextStyleのFontSizeプロパティでサイズをポイントで設定できます。
IronWordでRunオブジェクトの目的は何ですか?
IronWordのRunオブジェクトはTextContentのラッパーとして機能し、段落内でフォント、色、装飾などのテキストスタイルを細かいレベルで適用可能にします。
IronWordドキュメントでテキストを太字にするにはどうすればよいですか?
IronWordドキュメントでテキストを太字にするためには、TextStyleクラスのIsBoldプロパティをtrueに設定し、目的のテキストが含まれるRunオブジェクトに適用します。
IronWordでテキストをイタリックにするために使われるプロパティは何ですか?
IsItalicプロパティは、IronWordドキュメント内のテキストにイタリックフォーマットを適用するためにTextStyleクラス内で使用されます。
IronWordを使用してテキストに下線を引くにはどうすればよいですか?
IronWordドキュメントでテキストに下線を引くには、新しいUnderlineオブジェクトを作成し、テキストを含むRunオブジェクトのためにTextStyleクラスのUnderlineプロパティに割り当てます。
IronWordで複雑なテキストスタイリングを複数のプロパティを使って適用できますか?
はい、IronWordはTextStyleの複数のプロパティを組み合わせて複雑なテキストスタイリングを可能にし、Word文書内でリッチにフォーマットされたテキストを作成します。
DOCX文書でのテキストスタイリングにIronWordを使う利点は何ですか?
IronWordは、DOCX文書でのテキストスタイリングに対するプログラム的な制御を提供し、開発者が文書の作成を自動化しながら、Microsoft Wordと同様の一貫したプロフェッショナルなフォーマットを確保できます。
Ahmadは、C#、Python、およびウェブ技術に強い基盤を持つフルスタック開発者です。彼はスケーラブルなソフトウェアソリューションの構築に深い関心を持ち、デザインと機能が実際のアプリケーションでどのように融合するかを探求することを楽しんでいます。