مقدمة
Aspose.Slides FOSS for Python gives you full control over the PowerPoint presentation دورة الحياة - إنشاء الستائر من التجاعيد ، وإضافة وإعادة ترتيب الشرائح ، وتسجيلها مع الأشكال والجدول والنص المنسد، وتخزين النتيجة إلى PPTX، ODP، PDF، أو كل هذا يحدث في Python النقي مع لا تعتمد على Microsoft Office أو أي نوع من البنود الخارجية.
مكتبة متوفرة على PIPI كما aspose-slides-foss تحت رخصة MIT.Install مع ذلك مع pip, استيرادها, وبدء بناء العروض التقديمية في خطوط قليلة من الرمز. أنت تلقائي توليد التقارير، وبناء خط أنابيب سلاي ديك، أو إدراج إخراج العرض في تطبيق الويب، وتغطي API السطح الكامل: الشرائح مجموعات، ورقم / ترتيب، وجمع الشكل، وإطارات النص، وتعبئة تنسيقات، و خيارات التصدير.
يمر هذا المنشور من خلال القدرات الأساسية لإدارة العرض التقديمي - الفصول والأساليب التي ستستخدمها أكثر عند العمل مع الشرائح في Python.
ما هو مدرجة
عرض دورة الحياة
وَالْمُتَّقِينَ Presentation فئة هي نقطة الدخول.إنشاء سقف جديد، والتلاعب بمحتواه،, وتخزينها إلى أي تنسيق مدعوم.تدعم العروض التقديمية بروتوكول إدارة السياق،, يتم إطلاق الموارد تلقائياً.
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)
عمليات جمع الشرائح Slide Collection
SlideCollection يسمح لك إضافة، وإدخال، وتلون، إزالة، وعودة الأقراص. تُعدّد مؤشر العملة الداخلي بهذه الطريقة 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)
أشكال و أوتوماتيك
إضافة مستطيلات، إليبس، المثلثات وغيرها من أشكال الهندسة إلى أي شريحة عبر 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(),إعداد النص عبر الخلية 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])
table.rows[0][0].text_frame.text = "Name"
table.rows[0][1].text_frame.text = "Role"
table.rows[0][2].text_frame.text = "Team"
# Merge two cells in the second row
table.merge_cells(table.rows[1][0], table.rows[1][1], False)
# Style the header row borders
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.black
fmt.border_bottom.width = 2
الماجستير و Layout 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 الممتلكات لا تزال في الملف المحفوظ.
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 install aspose-slides-foss
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 | .ppt | — | المخطط |
| PPSX | .ppsx | — | المخطط |
| PPTM | .pptm | — | المخطط |
| POTX | .بوتكس | — | المخطط |
| ODP | .أودب | — | المخطط |
| — | المخطط | ||
| HTML | .html | — | المخطط |
| HTML5 | .html | — | المخطط |
| TIFF | .طيب | — | المخطط |
| GIF | .GIF | — | المخطط |
| XPS | .xps | — | المخطط |
| FODP | .فودب | — | المخطط |
| MD | .مـمـن | — | المخطط |
ملاحظة : في الوقت الحاضر يتم تنفيذ فقط تصدير PPTX. قيمة تنسيق أخرى موجودة في SaveFormat أندية متوافقة مع التقدم ولكنها غير وظيفية بعد. save() الطريقة دائما تولد PPTX الناتج بغض النظر عن معيار الشكل.
المصدر المفتوح و الترخيص
Aspose.Slides FOSS for Python is released under the MIT license. You can use it in المشاريع الشخصية والأكاديمية والتجارية دون قيود.الرمز المصدر هو متوفر على GitHub ويتم نشر الحزمة على PyPI.