クイックスタート

クイックスタート

クイックスタート

このガイドでは、Python 用の Aspose.Slides FOSS を使用して、インストールから保存された .pptx ファイルまでの最速の手順を示します。ライブラリは純粋な Python で、MIT ライセンスで提供され、Microsoft Office やネイティブバイナリは必要ありません。


前提条件

要件詳細
Python3.10 以降
OSWindows、macOS、Linux、Docker
Packageaspose-slides-foss から PyPI

Install

pip を使用して PyPI からパッケージをインストールします。バージョン 26.3.2 以降が必要です:

pip install aspose-slides-foss

プレゼンテーションを作成する

引数なしで Presentation を構築して空のデッキを作成します。ライブラリは自動的に空のスライドを 1 枚追加します。パスを指定して save() を呼び出し、SaveFormat.PPTX でファイルを書き込みます:

from aspose.slides_foss import Presentation
from aspose.slides_foss.export import SaveFormat

prs = Presentation()
prs.save("empty.pptx", SaveFormat.PPTX)

テキスト付きシェイプを追加

最初のスライドには prs.slides[0] でアクセスし、次に slide.shapes.add_auto_shape() を使って長方形を挿入します。テキストフレームを添付するには add_text_frame() を呼び出し、フォントプロパティは portion_format で設定します:

from aspose.slides_foss import Presentation, ShapeType
from aspose.slides_foss.export import SaveFormat

prs = Presentation()
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 400, 150)
tf = shape.add_text_frame("Hello from Aspose.Slides FOSS!")
tf.paragraphs[0].portions[0].portion_format.font_height = 24
prs.save("with_shape.pptx", SaveFormat.PPTX)

単色塗りつぶしを適用

fill_format.fill_type を FillType.SOLID に設定し、次に Color.from_argb() を使用して ARGB カラーを指定します。保存する前にその色がシェイプの背景に適用されます:

from aspose.slides_foss import Presentation, ShapeType, FillType
from aspose.slides_foss.export import SaveFormat
from aspose.slides_foss.drawing import Color

prs = Presentation()
shape = prs.slides[0].shapes.add_auto_shape(
    ShapeType.RECTANGLE, 100, 100, 400, 200
)
shape.fill_format.fill_type = FillType.SOLID
shape.fill_format.solid_fill_color.color = Color.from_argb(255, 70, 130, 180)
shape.add_text_frame("Styled shape")
prs.save("styled.pptx", SaveFormat.PPTX)

既存のファイルを読み込む

ファイルパスを Presentation コンストラクタに渡して既存の .pptx ファイルを開きます。スライド数を読み取り、必要に応じてデッキを変更し、最後に save() を呼び出して出力を書き込みます:

from aspose.slides_foss import Presentation
from aspose.slides_foss.export import SaveFormat

prs = Presentation("existing.pptx")
print(f"Slides: {len(prs.slides)}")
prs.save("copy.pptx", SaveFormat.PPTX)

次のステップ

参照

 日本語