הכניסה

מדריך זה מראה כיצד ליצור, לשנות ולשמור את ההצגות של PowerPoint באופן תכנית ב- Python באמצעות Aspose.Slides FOSS. הספרייה מאפשרת לך לבנות סלידים מתוך קפיצה, להוסיף ולהזמין סלדי, לאסוף אותם עם צורות, טבלאות וטקסט פורמט, ולחסן את התוצאה ל- PPTX. כל עיבוד מתרחש בפייטון טהור ללא תלות על Microsoft Office או כל בינארי חיצוני.

הספרייה זמינה ב-PyPI כ aspose-slides-foss תחת רישיון MIT.Install זה עם pip, לייבא אותו, ולהתחיל לבנות הצגות בכמה שורות של קוד. אתה אוטומטי ליצירת דיווחים, לבנות צינור משטח, או להדביק תוצאות הצגת יישום אינטרנט, ה- API מכסה את פני השטח המלא: slide אוסף, מפת ה- master/layout, אוספים צורות, מסגרות טקסט, פורמטים מלאים, ו אפשרויות ייצוא.

הפוסט הזה עובר דרך היכולות הבסיסיות של ניהול הצגה – הכיתות והשיטות שתשתמשו ביותר בעת עבודה עם סלידים ב- Python.


מה כולל

מחזור החיים של הצגה

The Presentation הקמת דק חדש, מניפולציה בתוכן שלו, והחסוך ל- PPTX. Presentation מנהל הקשר עם with לשחרר את הקבצים באופן אוטומטי.

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

with Presentation() as pres:
    # A new presentation starts with one blank slide
    print("Slides:", len(pres.slides))  # 1

    # Save to a file
    pres.save("output.pptx", SaveFormat.PPTX)

    # Or save to a stream
    buf = io.BytesIO()
    pres.save(buf, SaveFormat.PPTX)

סליד אוסף פעולות

SlideCollection תן לך להוסיף, להכניס, לקלון, להסיר ולהזמין מחדש את ה-slides. len(pres.slides) זה משקף את המספר הנוכחי לאחר כל שינוי.

from aspose.slides_foss import Presentation, ShapeType

with Presentation() as pres:
    layout = pres.layout_slides[0]

    # Add a blank slide using the first layout
    pres.slides.add_empty_slide(layout)

    # Insert at a specific position
    pres.slides.insert_empty_slide(1, layout)

    # Clone an existing slide (shapes are copied)
    pres.slides[0].shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 200, 100)
    pres.slides.add_clone(pres.slides[0])

    print("Total slides:", len(pres.slides))  # 4

    # Remove by index
    pres.slides.remove_at(3)

צורות ו- AutoShapes

הוסף ישרים, אליפסים, משולשים וצורות גיאומטריות אחרות לכל מסך באמצעות ShapeCollection.add_auto_shape().כל צורה מראה מיקום, גודל, סיבוב, ומלא את התכונות המתמשכות לאורך מחזורי ההצלה/העלאה.

from aspose.slides_foss import Presentation, ShapeType

with Presentation() as pres:
    slide = pres.slides[0]
    slide.shapes.clear()

    rect = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
    rect.rotation = 15

    ellipse = slide.shapes.add_auto_shape(ShapeType.ELLIPSE, 400, 50, 200, 200)

    # Reorder z-index
    slide.shapes.reorder(0, ellipse)
    print("Front shape:", slide.shapes[0].shape_type)  # ELLIPSE

שולחנות

יצירת טבלות נתונים עם ShapeCollection.add_table(),תגית: cell text via TextFrame, שילוב תאים, וליישם הגבול פורמט. גובה שורה ועמודה המגוון מתאים לערכים שאתה מביא למבנה.

from aspose.slides_foss import Presentation, FillType
from aspose.slides_foss.drawing import Color

with Presentation() as pres:
    slide = pres.slides[0]
    slide.shapes.clear()

    table = slide.shapes.add_table(50, 50, [150, 150, 150], [40, 40, 40])

    # Merge two cells in the second row
    table.merge_cells(table.rows[1][0], table.rows[1][1], False)

    # Style the header row with a bottom border
    for col_idx in range(len(table.columns)):
        fmt = table.rows[0][col_idx].cell_format
        fmt.border_bottom.fill_format.fill_type = FillType.SOLID
        fmt.border_bottom.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 0, 0)
        fmt.border_bottom.width = 2

מאסטר וליאוט Slides

לכל הצגה יש ייראקיה של סלידים מרכזיים וסלידי הפריסה. דרך Presentation.masters ו Presentation.layout_slides ליישם באופן עקבי צורה על כל הדק שלך.

from aspose.slides_foss import Presentation

with Presentation() as pres:
    master = pres.masters[0]
    print("Master layouts:", len(master.layout_slides))

    # Pick a layout by type
    from aspose.slides_foss import SlideLayoutType
    title_layout = pres.layout_slides.get_by_type(SlideLayoutType.TITLE)
    if title_layout:
        pres.slides.add_empty_slide(title_layout)

תכונות מסמך

לקרוא ולכתוב נתונים מוטאטיים כגון הכותרת, המחבר והנושא באמצעות DocumentProperties הגדרת כל אחד מהתכונות האלה לפני שיתקשר save() הם מוטבעים במתא נתונים PPTX וניתן לקרוא אותם באמצעות כלים מתחת לשטח:

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

with Presentation() as pres:
    props = pres.document_properties
    props.title = "Quarterly Report"
    props.author = "Engineering"
    props.subject = "Q1 2026 Results"

    pres.save("report.pptx", SaveFormat.PPTX)

מהיר התחלה

הפעל את פקודת ה-PIP הבאה כדי להתקין Aspose.Slides FOSS עבור Python מ- PyPI:

pip install aspose-slides-foss

הדוגמה הבאה יוצרת הצגת עם צורת כותרת, טבלת נתונים ומילוי, ולאחר מכן מאוחסנת ל- PPTX:

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

with Presentation() as pres:
    slide = pres.slides[0]
    slide.shapes.clear()

    # Add a title shape
    title = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 30, 860, 80)
    tf = title.add_text_frame("Quarterly Report")
    tf.paragraphs[0].portions[0].portion_format.font_bold = NullableBool.TRUE
    tf.paragraphs[0].portions[0].portion_format.font_height = 28

    # Add a data table
    table = slide.shapes.add_table(50, 150, [200, 200, 200], [40, 40, 40])
    headers = ["Region", "Revenue", "Growth"]
    for i, h in enumerate(headers):
        table.rows[0][i].text_frame.text = h

    # Fill the title shape background
    title.fill_format.fill_type = FillType.SOLID
    title.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 51, 102)

    # Save as PPTX
    pres.save("report.pptx", SaveFormat.PPTX)

פורמט תומך

פורמטהרחבהקראוכתוב
PPTX.pptx
PPT.PTTמתוכננת
PPSX.ppsxמתוכננת
PPTM.pptmמתוכננת
POTX.פוקסמתוכננת
ODP.ODPמתוכננת
PDF.pdfמתוכננת
HTML.HTMLמתוכננת
HTML5.HTMLמתוכננת
TIFF.טיףמתוכננת
GIF.GIFמתוכננת
XPS.xpsמתוכננת
FODP.פדפמתוכננת
MD.דקמתוכננת

הערה : PPTX קריאה וכתבה מתבצעת במלואה. SaveFormat ערכים (PPT, ODP, PDF, וכו ‘) מתוכננים עבור שחרורים עתידיים; העברת אותם ל save() כיום הוא מייצר את מוצרי PPTX.


קוד פתוח & רישיון

Aspose.Slides FOSS for Python is released under the MIT license. You can use it in פרויקטים אישיים, אקדמיים ומסחריים ללא הגבלות.הקוד המקור הוא: זמינים ב GitHub החבילה פורסמה על PyPI.


להתחיל

משאבים קשורים