سؤال

نحن نحاول إنشاء برنامج PowerPoint Slide برمجي. يمكننا الحصول على الرصاص على مستوى واحد ، ولكن اللعب بعلامات تبويب وإرجاع الخط لا يعمل مع التعدادات المتداخلة.

الآن نحصل على:

  • النص 1
  • subtext1
  • subtext2
  • النص 2

وما نريده هو:

  • النص 1
    • subtext1
    • subtext2
  • النص 2

هل هناك طريقة للتحكم في هذه باستخدام C# أو VBA؟

هل كانت مفيدة؟

المحلول

أولاً ، احصل على إشارة إلى Paragraphs التابع TextRange2, ، لأن كل عنصر تم نبضه هو فقرة (حقًا أ TextRange2).

Dim pres As Presentation
Set pres = Application.ActivePresentation

Dim slide As slide
Set slide = pres.Slides(2)

Dim shapes As shapes
Set shapes = slide.shapes

Dim textShape As Shape
Set textShape = shapes(2)

Dim textFrame As TextFrame2
Set textFrame = textShape.TextFrame2

Dim textRng As TextRange2
Set textRng = textFrame.textRange

Dim p As TextRange2
Set p = textRng.Paragraphs

SetIndent 1, p.Item(1)
SetIndent 2, p.Item(2)
SetIndent 2, p.Item(3)
SetIndent 1, p.Item(4)

تستدعي الأسطر الأربعة الأخيرة وظيفة تغلف منطق تعيين "مستوى" المسافة البادئة ، والذي يؤثر على نمط الرصاص والنص ، والمسافة البادئة الفعلية للرصاص والنص:

Private Function SetIndent(ByVal level As Integer, ByRef p As TextRange2)

p.ParagraphFormat.IndentLevel = level
p.ParagraphFormat.FirstLineIndent = 40
p.ParagraphFormat.LeftIndent = level * 40

End Function

من المؤكد أنه يمكنك إعادة تشكيل هذا لتلبية احتياجاتك - مثل تمرير عامل المسافة البادئة (لقد قمت بتشفيره على أنه 40 ، ولكن قد يختلف عدد الأميال الخاصة بك).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top