إدارة القوائم النقطية والمرقمة في العروض التقديمية في Python

نظرة عامة

Aspose.Slides for Python عبر .NET يسمح لك بإنشاء وتنسيق القوائم النقطية والمرقمة في عروض PowerPoint وOpenDocument. عنصر القائمة هو فقرة يتم التحكم في إعدادات الرصاصة الخاصة بها من خلال تنسيق الفقرة.

استخدم الخاصية Paragraph.paragraph_format للوصول إلى إعدادات القوائم على مستوى الفقرة. النقطة الرئيسية هي ParagraphFormat.bullet، التي تُعيد كائنًا من نوع BulletFormat. باستخدام هذا الكائن، يمكنك تعيين نوع الرصاصة، الرمز، الصورة، اللون، الحجم، نمط الترقيم، ورقم البداية.

تُظهر هذه المقالة كيفية:

  • إنشاء قائمة نقطية برمز مخصص
  • إنشاء رصاصة صورة
  • إنشاء قائمة متعددة المستويات عن طريق تعيين عمق الفقرة
  • إنشاء قائمة مرقمة
  • فحص وتغيير تنسيق القائمة في عرض تقديمي موجود
  • قراءة علامات القوائم الفعلية والأرقام جنبًا إلى جنب مع نص الفقرة

إنشاء قائمة نقطية

لإنشاء قائمة نقطية، أضف كائنات Paragraph إلى TextFrame واضبط BulletFormat.type إلى BulletType.SYMBOL. يمكنك بعد ذلك ضبط BulletFormat.char، BulletFormat.color، وBulletFormat.height للتحكم في مظهر الرصاصة.

الكود التالي بلغة Python يوضح كيفية إنشاء قائمة نقطية في شريحة:

import aspose.slides as slides

def create_paragraph(text):
    paragraph = slides.Paragraph()
    paragraph.paragraph_format.bullet.type = slides.BulletType.SYMBOL
    paragraph.paragraph_format.bullet.char = '*'
    paragraph.paragraph_format.indent = 15
    paragraph.paragraph_format.bullet.is_bullet_hard_color = slides.NullableBool.TRUE
    paragraph.paragraph_format.bullet.color.color = slides.Color.indian_red
    paragraph.paragraph_format.bullet.height = 100
    paragraph.text = text
    return paragraph


with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 20, 200, 50)

    text_frame = auto_shape.text_frame
    text_frame.paragraphs.clear()

    paragraph1 = create_paragraph("The first paragraph")
    text_frame.paragraphs.add(paragraph1)

    paragraph2 = create_paragraph("The second paragraph")
    text_frame.paragraphs.add(paragraph2)

    presentation.save("symbol_bullets.pptx", slides.export.SaveFormat.PPTX)

النتيجة:

الرموز النقطية

إنشاء قائمة مرقمة

استخدم القوائم المرقمة عندما يكون ترتيب العناصر مهمًا. اضبط BulletFormat.type إلى BulletType.NUMBERED. يمكنك أيضًا اختيار تنسيق الترقيم باستخدام BulletFormat.numbered_bullet_style أو ضبط BulletFormat.numbered_bullet_start_with عندما ينبغي أن تبدأ القائمة من قيمة غير 1.

الكود التالي بلغة Python يوضح كيفية إنشاء قائمة مرقمة في شريحة:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 20, 90, 80)

    text_frame = auto_shape.text_frame
    text_frame.paragraphs.clear()

    paragraph1 = slides.Paragraph()
    paragraph1.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    paragraph1.text = "Apple"
    text_frame.paragraphs.add(paragraph1)

    paragraph2 = slides.Paragraph()
    paragraph2.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    paragraph2.text = "Orange"
    text_frame.paragraphs.add(paragraph2)

    paragraph3 = slides.Paragraph()
    paragraph3.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    paragraph3.text = "Banana"
    text_frame.paragraphs.add(paragraph3)

    presentation.save("numbered_bullets.pptx", slides.export.SaveFormat.PPTX)

النتيجة:

الرموز المرقمة

إنشاء رصاصة صورة

Aspose.Slides يتيح لك استبدال رمز الرصاصة العادي بصورة. تعمل رصاصات الصورة بشكل أفضل مع صور بسيطة تظل قابلة للقراءة بحجم صغير، مثل الأيقونات أو ملفات PNG الشفافة الصغيرة.

لإنشاء رصاصة صورة، أضف صورة إلى Presentation.images وعيّن كائن الصورة المرتجع إلى BulletFormat.picture. اضبط BulletFormat.type إلى BulletType.PICTURE قبل تعيين الصورة.

لنفترض أن لدينا ملفًا اسمه “image.png”:

صورة للرصاصات

الكود التالي بلغة Python يوضح كيفية إنشاء رصاصات صورة في شريحة:

import aspose.slides as slides

def create_paragraph(text, image):
    paragraph = slides.Paragraph()
    paragraph.paragraph_format.bullet.type = slides.BulletType.PICTURE
    paragraph.paragraph_format.bullet.picture.image = image
    paragraph.paragraph_format.indent = 15
    paragraph.paragraph_format.bullet.height = 100
    paragraph.text = text
    return paragraph


with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 20, 200, 50)

    text_frame = auto_shape.text_frame
    text_frame.paragraphs.clear()

    with open("image.png", "rb") as image_stream:
        bullet_image = presentation.images.add_image(image_stream)

    paragraph1 = create_paragraph("The first paragraph", bullet_image)
    text_frame.paragraphs.add(paragraph1)

    paragraph2 = create_paragraph("The second paragraph", bullet_image)
    text_frame.paragraphs.add(paragraph2)

    presentation.save("picture_bullets.pptx", slides.export.SaveFormat.PPTX)

النتيجة:

رصاصات الصورة

إنشاء قائمة متعددة المستويات

استخدم ParagraphFormat.depth لتحديد العناصر على مستويات مختلفة. المستوى 0 هو المستوى العلوي، المستوى 1 يكون متداخلًا تحته، وهكذا. يتحكم العمق في الإزاحة فقط؛ اضبط ParagraphFormat.bullet على كل فقرة عندما يجب أن تحمل المستويات أيضًا رصاصات.

الكود التالي بلغة Python يوضح كيفية إنشاء قائمة متعددة المستويات:

import aspose.slides as slides

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 20, 260, 110)

    text_frame = auto_shape.text_frame
    text_frame.paragraphs.clear()

    paragraph1 = slides.Paragraph()
    paragraph1.paragraph_format.depth = 0
    paragraph1.text = "My text - Depth 0"
    text_frame.paragraphs.add(paragraph1)

    paragraph2 = slides.Paragraph()
    paragraph2.paragraph_format.depth = 1
    paragraph2.text = "My text - Depth 1"
    text_frame.paragraphs.add(paragraph2)

    paragraph3 = slides.Paragraph()
    paragraph3.paragraph_format.depth = 2
    paragraph3.text = "My text - Depth 2"
    text_frame.paragraphs.add(paragraph3)

    paragraph4 = slides.Paragraph()
    paragraph4.paragraph_format.depth = 3
    paragraph4.text = "My text - Depth 3"
    text_frame.paragraphs.add(paragraph4)

    presentation.save("multilevel_bullets.pptx", slides.export.SaveFormat.PPTX)

النتيجة:

القائمة متعددة المستويات

تغيير قائمة موجودة

لتغيير تنسيق القائمة في عرض تقديمي موجود، احصل على الفقرة المستهدفة وقم بتحديث إعدادات ParagraphFormat.bullet. يمكن استخدام نفس الخصائص المستخدمة لإنشاء القوائم لفحص أو تعديل القوائم التي تم تحميلها من ملف PPT أو PPTX أو ODP.

import aspose.slides as slides

with slides.Presentation("input.pptx") as presentation:
    slide = presentation.slides[0]

    auto_shape = slide.shapes[0]

    paragraph = auto_shape.text_frame.paragraphs[0]
    paragraph.paragraph_format.bullet.type = slides.BulletType.NUMBERED
    paragraph.paragraph_format.bullet.numbered_bullet_style = slides.NumberedBulletStyle.BULLET_ROMAN_UC_PERIOD
    paragraph.paragraph_format.bullet.numbered_bullet_start_with = 1
    paragraph.paragraph_format.margin_left = 30
    paragraph.paragraph_format.indent = -20

    presentation.save("updated_list.pptx", slides.export.SaveFormat.PPTX)

قراءة القيم الفعلية للرصاصات

عند استخراج محتوى العرض التقديمي، احرص على إبقاء علامات القوائم جنبًا إلى جنب مع نص الفقرة. استدعِ ParagraphFormat.get_effective وابدأ بـ IParagraphFormatEffectiveData.bullet للحصول على تنسيق الرصاصة الفعلي. تحقق من type قبل قراءة actual_bullet_value.

بالنسبة للقوائم المرقمة، ميز بين القيم الثلاث التالية:

  • numbered_bullet_style يحدد التنسيق، مثل الأرقام العربية متبوعة بنقطة أو الأحرف الصغيرة متبوعة بنقطة.
  • numbered_bullet_start_with يحدد رقم البداية لمجموعة من الفقرات المرقمة.
  • actual_bullet_value يُرجِع العلامة المنسقة لفقرة معينة. على سبيل المثال، العنصر الثاني في قائمة تبدأ من 5 يُعيد 6..

احفظ depth مع كل فقرة للحفاظ على مستوى التداخل. العلامة الفعلية لا تُشفر التسلسل الكامل: قد تُعيد عنصرًا متداخلًا c. بدلاً من تسمية مركبة مثل 6.c..

import aspose.slides as slides

with slides.Presentation() as presentation:
    presentation.slide_size.set_size(720, 440, slides.SlideSizeScaleType.DO_NOT_SCALE)
    slide = presentation.slides[0]

    shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 20, 660, 400)
    shape.fill_format.fill_type = slides.FillType.NO_FILL
    shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL

    text_frame = shape.text_frame
    text_frame.paragraphs.clear()

    # إنشاء علامة صورة بدون ملف صورة خارجي.
    svg = slides.SvgImage("<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><rect width='16' height='16' rx='4' fill='#0078D4'/></svg>")
    bullet_image = presentation.images.add_image(svg)

    def add_paragraph(text, depth, bullet_type, start=1, style=slides.NumberedBulletStyle.BULLET_ARABIC_PERIOD):
        paragraph = slides.Paragraph()
        paragraph.text = text

        paragraph_format = paragraph.paragraph_format
        paragraph_format.depth = depth
        paragraph_format.margin_left = 30 + depth * 40
        paragraph_format.indent = -28
        paragraph_format.space_after = 8
        paragraph_format.default_portion_format.font_height = 22
        paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
        paragraph_format.default_portion_format.fill_format.solid_fill_color.color = slides.Color.black
        paragraph_format.bullet.type = bullet_type
        paragraph_format.bullet.is_bullet_hard_color = slides.NullableBool.TRUE
        paragraph_format.bullet.color.color = slides.Color.black
        if bullet_type == slides.BulletType.NUMBERED:
            paragraph_format.bullet.numbered_bullet_style = style
            paragraph_format.bullet.numbered_bullet_start_with = start
        elif bullet_type == slides.BulletType.SYMBOL:
            paragraph_format.bullet.char = "\u2022"
        elif bullet_type == slides.BulletType.PICTURE:
            paragraph_format.bullet.picture.image = bullet_image

        text_frame.paragraphs.add(paragraph)

    add_paragraph("First item", 0, slides.BulletType.NUMBERED, 5)
    add_paragraph("Second item", 0, slides.BulletType.NUMBERED, 5)
    add_paragraph("Nested item", 1, slides.BulletType.NUMBERED, 3, slides.NumberedBulletStyle.BULLET_ALPHA_LC_PERIOD)
    add_paragraph("Next nested item", 1, slides.BulletType.NUMBERED, 3, slides.NumberedBulletStyle.BULLET_ALPHA_LC_PERIOD)
    add_paragraph("Deep item", 2, slides.BulletType.NUMBERED, 4, slides.NumberedBulletStyle.BULLET_ROMAN_LC_PERIOD)
    add_paragraph("Back to top level", 0, slides.BulletType.NUMBERED, 5)
    add_paragraph("Symbol marker", 0, slides.BulletType.SYMBOL)
    add_paragraph("No bullet", 0, slides.BulletType.NONE)
    add_paragraph("Picture marker", 0, slides.BulletType.PICTURE)
    presentation.save("actual_bullet_values.pptx", slides.export.SaveFormat.PPTX)

with slides.Presentation("actual_bullet_values.pptx") as loaded_presentation:
    loaded_shape = loaded_presentation.slides[0].shapes[0]
    bullet_type_names = {slides.BulletType.NUMBERED: "NUMBERED", slides.BulletType.SYMBOL: "SYMBOL", slides.BulletType.NONE: "NONE", slides.BulletType.PICTURE: "PICTURE"}
    print("Text | Depth | Type | Actual value")
    for paragraph in loaded_shape.text_frame.paragraphs:
        bullet = paragraph.paragraph_format.get_effective().bullet
        if bullet.type in (slides.BulletType.NUMBERED, slides.BulletType.SYMBOL):
            marker = bullet.actual_bullet_value
        elif bullet.type == slides.BulletType.NONE:
            marker = f"{bullet.actual_bullet_value} (no bullet)"
        elif bullet.type == slides.BulletType.PICTURE:
            marker = f"{bullet.actual_bullet_value} (image required)"
        else:
            marker = "unsupported bullet type"
        bullet_type_name = bullet_type_names.get(bullet.type, "UNKNOWN")
        print(f"{paragraph.text} | {paragraph.paragraph_format.depth} | {bullet_type_name} | {marker}")

القوائم المصدرية موضحة أدناه.

قوائم تبدأ من 5، عناصر بأحرف متداخلة ورومانية، علامة رمز، فقرة بدون رصاصة، وعلامة صورة زرقاء

التقرير يتطابق مع العلامات المعروضة في PowerPoint:

Text | Depth | Type | Actual value
First item | 0 | NUMBERED | 5.
Second item | 0 | NUMBERED | 6.
Nested item | 1 | NUMBERED | c.
Next nested item | 1 | NUMBERED | d.
Deep item | 2 | NUMBERED | iv.
Back to top level | 0 | NUMBERED | 7.
Symbol marker | 0 | SYMBOL | •
No bullet | 0 | NONE | None (no bullet)
Picture marker | 0 | PICTURE | None (image required)

بالنسبة إلى BulletType.NONE and BulletType.PICTURE، تُعيد actual_bullet_value None، وليس سلسلة فارغة. عالج هذه الأنواع بشكل منفصل: الأولى ليس لها علامة، بينما تتطلب الثانية استخراج صورة الرصاصة بشكل منفصل. لا يمكن تمثيل رصاصة الصورة فقط باستخراج علامة نصية.

الأسئلة المتكررة

هل يمكن تصدير القوائم النقطية والمرقمة إلى PDF أو صور؟

نعم. Aspose.Slides يحافظ على تنسيق القائمة عندما يدعم تنسيق الهدف تخطيط النص وميزات الرصاصة المقابلة.

هل يمكن تعديل القوائم في العروض التقديمية الموجودة؟

نعم. حمِّل العرض التقديمي، وصل إلى الفقرة المستهدفة، افحص أو حدّث إعدادات ParagraphFormat.bullet، ثم احفظ العرض التقديمي.

هل يمكن للقوائم أن تحتوي على نص غير لاتيني؟

نعم. يمكن أن يحتوي نص عناصر القائمة على أحرف Unicode، وبالتالي يمكنك إنشاء قوائم في عروض تقديمية متعددة اللغات. تأكد من أن الخطوط المستخدمة في العرض تدعم الأحرف التي تحتاجها.