このトピックでは、Python を使用して PowerPoint でテキストを強調表示するプロセスを説明します。これには、IDE の設定方法の詳細、プログラミング手順のリスト、Python** を使用して **presentation ハイライト ツールを開発するためのコード例が含まれています。さまざまなオプションを使用して、強調表示する目的のテキストを検索する方法を学びます。
Python を使用して PowerPoint で強調表示する手順
- .NET 経由の Python 用 Aspose.Slides を使用してテキストをハイライトする環境を確立します
- Presentation クラスのインスタンスを使用して空のプレゼンテーションを作成し、その最初のデフォルト スライドにアクセスします
- Rectangle タイプの Autoshape を追加し、サンプル テキストを含むテキスト フレームを挿入します。
- 追加されたテキストフレーム内の目的のテキストを、highlight_text メソッドを使用して強調表示します。
- 強調表示されたテキストを含むプレゼンテーションをディスクに保存します
前述の手順は、Python* を使用して PPTX または *PPT ハイライターを開発するプロセスを要約したものです。 PowerPoint プレゼンテーション ファイルを読み込むか、Presentation クラスのインスタンスを使用して新しいプレゼンテーション ファイルを作成し、その最初のデフォルト スライドにアクセスすることができます。サンプル テキストをテキスト フレームに追加して、スライド内にオートシェイプを作成します。その後、highlight_text メソッドを使用してテキストの必要な部分を強調表示します。最後に、強調表示されたテキストを含むプレゼンテーションがディスクに保存されます。
Python を使用して PowerPoint プレゼンテーション ハイライターを開発するコード
import aspose.pydrawing as draw | |
import aspose.slides as slides | |
filepath = "C://Words//" | |
# Applying the license for Aspose.Slides | |
LicForHighlight = slides.License() | |
LicForHighlight.set_license(filepath + "Total.lic") | |
# Generate an default empty presentation using the Presentation class object | |
with slides.Presentation() as samplePres: | |
# Load the first default slide of the newly created presentation | |
slideForText = samplePres.slides[0] | |
# Insert an auto-shape to highlight text | |
aShapeHighlight = slideForText.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 150, 300, 200) | |
# Set the auto-shape fill type to no fill color | |
aShapeHighlight.fill_format.fill_type = slides.FillType.NO_FILL | |
#Insert sample text inside the text frame | |
aShapeHighlight.add_text_frame("students of the class. students to join session") | |
#Add the text highlight options | |
highlightOptions = slides.TextHighlightingOptions() | |
highlightOptions.whole_words_only = False | |
highlightOptions.case_sensitive = True | |
# Highlight all words inside the shape text frame containing 'students' | |
aShapeHighlight.text_frame.highlight_text("students", draw.Color.red, highlightOptions) | |
#Save the presentation with highlighted text on the disk | |
samplePres.save(filepath + "HighlightText.pptx", slides.export.SaveFormat.PPTX) | |
print("Done") |
この例では、Python を使用して PowerPoint で強調表示する方法を示します。ターゲット文字列を含むすべての文字列を強調表示する必要がある場合は、ターゲット文字列でhighlight_text()メソッドを使用し、テキストを強調表示します。テキストの検索と強調表示に、whole_words_only や case_sensitive などの強調表示テキスト設定を使用することで、テキストの強調表示を強化できます。
この単純なトピックは、Python* を使用して *プレゼンテーション ハイライト ツールを開発する方法を教えてくれました。プレゼンテーション内のテキストに取り消し線を付ける場合は、Pythonを使用してPPTXのテキストに取り消し線を引く方法 の記事を参照してください。