この短いチュートリアルでは、Python を使用して Word で段落の書式を設定する方法 について説明します。IDE 設定、手順の一覧、および Python で段落を記述する形式 を変更するためのサンプル コードが含まれています。さまざまな書式設定プロパティの設定方法と、デフォルト値を設定するために書式設定をクリアする方法を学習します。
Python で段落の書き方を設定する手順
- .NET 経由の Python 用 Aspose.Words を使用してテキストをフォーマットするための IDE を設定します
- テキストのインデントとフォーマットに Document クラスを使用して新しいワールドファイルを作成します。
- 上記のWordファイルのDocumentBuilderクラスオブジェクトを作成します。
- paragraph_formatプロパティを使用して配置、インデント、間隔を設定します。
- 境界線とフォントのプロパティを設定する
- writeln() メソッドを使用して段落に必要なテキストを記述します。
- 出力したWordファイルを保存する
これらの手順では、Python で段落をインデントする方法とその他のパラメータの設定について詳しく説明します。プロセスを開始するには、Word ファイルを作成し、DocumentBuilder オブジェクトをそのファイルにリンクし、段落形式のプロパティにアクセスして、配置、インデント、前後のスペース、境界線のスタイル、フォントの色、太字フラグ、サイズを設定します。最後に、段落のテキストを入力して、出力 Word ファイルを保存します。
Python で文章の段落形式を変更するコード
import aspose.words as aw | |
import aspose.pydrawing as drawing | |
# Load the license | |
wordLic = aw.License() | |
wordLic.set_license("license.lic") | |
newDoc = aw.Document() | |
builder = aw.DocumentBuilder(newDoc) | |
# Set formatting | |
paragraphFormat = builder.paragraph_format | |
paragraphFormat.alignment = aw.ParagraphAlignment.JUSTIFY | |
paragraphFormat.left_indent = 45 | |
paragraphFormat.right_indent = 45 | |
paragraphFormat.space_after = 20 | |
paragraphFormat.borders.horizontal.line_style = aw.LineStyle.DOUBLE | |
paragraphFormat.style.font.size = 12 | |
paragraphFormat.style.font.bold = True | |
paragraphFormat.style.font.color = drawing.Color.blue | |
# Output text | |
builder.writeln("Word paragraph formatting refers to adjusting the appearance and layout of paragraphs in a document to improve readability and presentation.") | |
builder.writeln("Word also provides options to control spacing before and after paragraphs, which helps in creating visually appealing documents with clear structure.") | |
newDoc.save("Formatted.docx") | |
print ("Text formatted") |
このコードは、Python を使用して Word で段落をインデントする方法 を示しています。DocumentBuilder オブジェクトを Word 文書にリンクすると、段落の書式設定プロパティにアクセスして、必要に応じて表示または更新できるようになります。Word の折り返し、スタイル名、網掛け、アウトライン レベル、ドロップ キャップの位置、境界線の幅、線のスタイル、テーマの色を設定できます。
この短いチュートリアルでは、Microsoft Word の段落書式を Python で書式設定する方法について説明します。Word ファイルに箇条書きを挿入する場合は、Python を使用して Word に箇条書きを挿入する の記事を参照してください。