この短いガイドは、C# を使用して Word で 段落書式を設定する のに役立ちます。IDE を設定するための詳細、手順の一覧、および C# を使用して MS Word の 段落書式を変更する ためのサンプル コードが含まれています。さまざまなプロパティについて説明し、段落書式、境界線、およびスタイルのカスタマイズを示します。
C# を使用して段落の書き方を設定する手順
- IDE で Aspose.Words for .NET を使用してテキストをフォーマットするように設定します
- 段落書式を設定するための Document クラスを使用して新しい Word ファイルを作成します。
- 上記のWord文書を使用してDocumentBuilderクラスオブジェクトを作成します。
- 段落書式のインデントと配置プロパティを設定する
- 段落の境界線とフォントの設定
- 上記の段落の書式をチェックするためのテキストを追加します
- Save 書式設定されたテキストを含む新しい Word ファイル
これらの手順では、C# を使用して Word 文書の段落書式を設定する方法について説明します。新しい Word 文書を作成し、DocumentBuilder オブジェクトをアタッチして、ParagraphFormat プロパティにアクセスし、配置、左インデント、右インデント、および後のスペースを設定します。同様に、境界線や、サイズ、色、太字などのフォント プロパティを設定することもできます。
C# を使用して Microsoft Word の段落書式を設定するコード
using Aspose.Words; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
License lic = new License(); | |
lic.SetLicense("license.lic"); | |
Document document = new Document(); | |
DocumentBuilder docBuilder = new DocumentBuilder(document); | |
// Set formatting | |
ParagraphFormat paragraphFormat = docBuilder.ParagraphFormat; | |
paragraphFormat.Alignment = ParagraphAlignment.Justify; | |
paragraphFormat.LeftIndent = 45; | |
paragraphFormat.RightIndent = 45; | |
paragraphFormat.SpaceAfter = 20; | |
paragraphFormat.Borders.Horizontal.LineStyle = LineStyle.Double; | |
paragraphFormat.Style.Font.Size = 12; | |
paragraphFormat.Style.Font.Color = System.Drawing.Color.Blue; | |
paragraphFormat.Style.Font.Bold = true; | |
// Output text | |
docBuilder.Writeln("Text formatting in a Word file allows users to enhance the appearance of their documents, making them more readable and visually appealing. Common formatting options include changing the font type and size, applying bold, italics, or underline for emphasis, and adjusting text alignment (left, center, right, or justified)."); | |
docBuilder.Writeln("You can also modify line spacing, add bullet points or numbered lists, and use indentation to organize content."); | |
document.Save("Output.docx"); | |
System.Console.WriteLine("Paragraph formatted in Word file"); | |
} | |
} |
このコード セグメントは、C# を使用して段落をインデントする方法を示しています。ドキュメントの DocumentBuilder オブジェクトを作成すると、ParagraphFormat などのすべてのプロパティにアクセスできます。また、ページ設定、配置、行間、改ページ、網掛け、単語の折り返しを設定したり、必要に応じて 1 つのコマンドで書式をクリアしたりすることもできます。
この記事では、新規または既存の Word ファイルの書式設定について説明しました。Word ファイルのヘッダーとフッターを削除する場合は、C# を使用して Word のヘッダーとフッターを削除する の記事を参照してください。