Beheer opsomming- en genummerde lijsten in presentaties in C++
Overzicht
Aspose.Slides for C++ stelt u in staat om opsomming‑ en genummerde lijsten te maken en op te maken in PowerPoint‑ en OpenDocument‑presentaties. Een lijstitem is een alinea waarvan de opsomminginstellingen worden beheerd via de alinea‑indeling.
Gebruik de IParagraph::get_ParagraphFormat‑methode om lijstinstellingen op alineaniveau te benaderen. Het belangrijkste toegangspunt is IParagraphFormat::get_Bullet, die een IBulletFormat‑object retourneert. Met dit object kunt u het opsommingstype, symbool, afbeelding, kleur, grootte, nummeringsstijl en beginnummer instellen.
Dit artikel laat zien hoe u:
- een opsomminglijst met een aangepast symbool maken
- een afbeelding‑opsomming maken
- een meerlagige lijst maken door de alinea‑diepte in te stellen
- een genummerde lijst maken
- de lijstopmaak in een bestaande presentatie inspecteren en wijzigen
- de werkelijke lijstmarkeringen en cijfers lezen naast de alinea‑tekst
Maak een opsomminglijst
Om een opsomminglijst te maken, voegt u Paragraph‑objecten toe aan een ITextFrame en stelt u IBulletFormat::set_Type in op BulletType::Symbol. Vervolgens kunt u IBulletFormat::set_Char, IBulletFormat::get_Color en IBulletFormat::set_Height instellen om het uiterlijk van de opsomming te regelen.
De volgende C++‑code toont hoe u een opsomminglijst in een dia maakt:
#include <DOM/BulletType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IBulletFormat.h>
#include <DOM/IColorFormat.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/NullableBool.h>
#include <DOM/Paragraph.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;
auto createParagraph = [](System::String text)
{
auto paragraph = System::MakeObject<Paragraph>();
auto paragraphFormat = paragraph->get_ParagraphFormat();
auto bulletFormat = paragraphFormat->get_Bullet();
bulletFormat->set_Type(BulletType::Symbol);
bulletFormat->set_Char(u'*');
paragraphFormat->set_Indent(15);
bulletFormat->set_IsBulletHardColor(NullableBool::True);
bulletFormat->get_Color()->set_Color(System::Drawing::Color::get_IndianRed());
bulletFormat->set_Height(100);
paragraph->set_Text(text);
return paragraph;
};
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto autoShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 20, 200, 50);
auto textFrame = autoShape->get_TextFrame();
textFrame->get_Paragraphs()->Clear();
auto paragraph1 = createParagraph(u"The first paragraph");
textFrame->get_Paragraphs()->Add(paragraph1);
auto paragraph2 = createParagraph(u"The second paragraph");
textFrame->get_Paragraphs()->Add(paragraph2);
presentation->Save(u"symbol_bullets.pptx", SaveFormat::Pptx);
presentation->Dispose();
Het resultaat:

Genummerde lijst maken
Gebruik genummerde lijsten wanneer de volgorde van items van belang is. Stel IBulletFormat::set_Type in op BulletType::Numbered. U kunt ook een nummeringsopmaak kiezen met IBulletFormat::set_NumberedBulletStyle of IBulletFormat::set_NumberedBulletStartWith instellen wanneer de lijst moet beginnen met een andere waarde dan 1.
De volgende C++‑code laat zien hoe u een genummerde lijst in een dia maakt:
#include <DOM/BulletType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IBulletFormat.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Paragraph.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto autoShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 20, 90, 80);
auto textFrame = autoShape->get_TextFrame();
textFrame->get_Paragraphs()->Clear();
auto paragraph1 = System::MakeObject<Paragraph>();
paragraph1->get_ParagraphFormat()->get_Bullet()->set_Type(BulletType::Numbered);
paragraph1->set_Text(u"Apple");
textFrame->get_Paragraphs()->Add(paragraph1);
auto paragraph2 = System::MakeObject<Paragraph>();
paragraph2->get_ParagraphFormat()->get_Bullet()->set_Type(BulletType::Numbered);
paragraph2->set_Text(u"Orange");
textFrame->get_Paragraphs()->Add(paragraph2);
auto paragraph3 = System::MakeObject<Paragraph>();
paragraph3->get_ParagraphFormat()->get_Bullet()->set_Type(BulletType::Numbered);
paragraph3->set_Text(u"Banana");
textFrame->get_Paragraphs()->Add(paragraph3);
presentation->Save(u"numbered_bullets.pptx", SaveFormat::Pptx);
presentation->Dispose();
Het resultaat:

Afbeeldings‑opsomming maken
Aspose.Slides stelt u in staat om een regulier opsombingssymbool te vervangen door een afbeelding. Afbeeldings‑opsommingen werken het best met eenvoudige afbeeldingen die ook op klein formaat leesbaar blijven, zoals pictogrammen of kleine doorzichtige PNG‑bestanden.
Note
Idealiter, als u van plan bent het reguliere opsombingssymbool door een afbeelding te vervangen, kiest u het beste een eenvoudige afbeelding met een transparante achtergrond. Dergelijke afbeeldingen werken goed als aangepaste opsombingssymbolen.
Houd er rekening mee dat de afbeelding wordt verkleind tot een zeer klein formaat. Om die reden raden wij sterk aan een afbeelding te kiezen die duidelijk en visueel effectief blijft wanneer deze als opsomming in een lijst wordt gebruikt.
Om een afbeeldings‑opsomming te maken, voegt u een afbeelding toe aan IPresentation::get_Images en kent u het geretourneerde IPPImage‑object toe aan IBulletFormat::get_Picture. Stel IBulletFormat::set_Type in op BulletType::Picture voordat u de afbeelding toewijst.
Stel dat we een “image.png” hebben:

De volgende C++‑code laat zien hoe u afbeeldings‑opsommingen in een dia maakt:
#include <DOM/BulletType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IBulletFormat.h>
#include <DOM/IImageCollection.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/ITextFrame.h>
#include <DOM/Paragraph.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <IImage.h>
#include <Util/Images.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
auto createParagraph = [](System::String text, System::SharedPtr<IPPImage> image)
{
auto paragraph = System::MakeObject<Paragraph>();
auto paragraphFormat = paragraph->get_ParagraphFormat();
auto bulletFormat = paragraphFormat->get_Bullet();
bulletFormat->set_Type(BulletType::Picture);
bulletFormat->get_Picture()->set_Image(image);
paragraphFormat->set_Indent(15);
bulletFormat->set_Height(100);
paragraph->set_Text(text);
return paragraph;
};
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto autoShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 20, 200, 50);
auto textFrame = autoShape->get_TextFrame();
textFrame->get_Paragraphs()->Clear();
auto sourceImage = Images::FromFile(u"image.png");
auto bulletImage = presentation->get_Images()->AddImage(sourceImage);
sourceImage->Dispose();
auto paragraph1 = createParagraph(u"The first paragraph", bulletImage);
textFrame->get_Paragraphs()->Add(paragraph1);
auto paragraph2 = createParagraph(u"The second paragraph", bulletImage);
textFrame->get_Paragraphs()->Add(paragraph2);
presentation->Save(u"picture_bullets.pptx", SaveFormat::Pptx);
presentation->Dispose();
Het resultaat:

Meerlagige lijst maken
Gebruik IParagraphFormat::set_Depth om lijstitems op verschillende niveaus te plaatsen. Niveau 0 is het bovenste niveau, niveau 1 is eronder genesteld, enzovoort.
De volgende C++‑code laat zien hoe u een meerlagige opsomminglijst maakt:
#include <DOM/IAutoShape.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Paragraph.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto autoShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 20, 260, 110);
auto textFrame = autoShape->get_TextFrame();
textFrame->get_Paragraphs()->Clear();
auto paragraph1 = System::MakeObject<Paragraph>();
paragraph1->get_ParagraphFormat()->set_Depth(0);
paragraph1->set_Text(u"My text - Depth 0");
textFrame->get_Paragraphs()->Add(paragraph1);
auto paragraph2 = System::MakeObject<Paragraph>();
paragraph2->get_ParagraphFormat()->set_Depth(1);
paragraph2->set_Text(u"My text - Depth 1");
textFrame->get_Paragraphs()->Add(paragraph2);
auto paragraph3 = System::MakeObject<Paragraph>();
paragraph3->get_ParagraphFormat()->set_Depth(2);
paragraph3->set_Text(u"My text - Depth 2");
textFrame->get_Paragraphs()->Add(paragraph3);
auto paragraph4 = System::MakeObject<Paragraph>();
paragraph4->get_ParagraphFormat()->set_Depth(3);
paragraph4->set_Text(u"My text - Depth 3");
textFrame->get_Paragraphs()->Add(paragraph4);
presentation->Save(u"multilevel_bullets.pptx", SaveFormat::Pptx);
presentation->Dispose();
Het resultaat:

Bestaande lijst wijzigen
Om de lijstopmaak in een bestaande presentatie te wijzigen, krijgt u de doel‑alinea en werkt u de instellingen van IParagraphFormat::get_Bullet bij. Dezelfde eigenschappen die worden gebruikt om lijsten te maken, kunnen worden gebruikt om lijsten die uit een PPT‑, PPTX‑ of ODP‑bestand zijn geladen, te inspecteren of te wijzigen.
De volgende C++‑code wijzigt de eerste alinea in een tekstframe zodat deze een genummerde lijststijl gebruikt:
#include <DOM/BulletType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IBulletFormat.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/NumberedBulletStyle.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
auto presentation = System::MakeObject<Presentation>(u"input.pptx");
auto slide = presentation->get_Slide(0);
auto autoShape = System::ExplicitCast<IAutoShape>(slide->get_Shape(0));
auto paragraph = autoShape->get_TextFrame()->get_Paragraph(0);
auto paragraphFormat = paragraph->get_ParagraphFormat();
auto bulletFormat = paragraphFormat->get_Bullet();
bulletFormat->set_Type(BulletType::Numbered);
bulletFormat->set_NumberedBulletStyle(NumberedBulletStyle::BulletRomanUCPeriod);
bulletFormat->set_NumberedBulletStartWith(1);
paragraphFormat->set_MarginLeft(30);
paragraphFormat->set_Indent(-20);
presentation->Save(u"updated_list.pptx", SaveFormat::Pptx);
presentation->Dispose();
Werkelijke opsommingwaarden lezen
Bij het extraheren van presentatiewaarde, behoudt u lijstmarkeringen naast de alinea‑tekst. Roep IParagraphFormat::GetEffective aan en krijg toegang tot IParagraphFormatEffectiveData::get_Bullet om het effectieve opsombingsformaat te verkrijgen. Controleer zijn get_Type vóór het lezen van get_ActualBulletValue.
Voor genummerde lijsten onderscheidt u deze drie waarden:
- get_NumberedBulletStyle bepaalt het formaat, bijvoorbeeld Arabische cijfers gevolgd door een punt of kleine letters gevolgd door een punt.
- get_NumberedBulletStartWith geeft het beginnummer op voor een groep genummerde alinea’s.
- get_ActualBulletValue retourneert de opgemaakte marker voor een specifieke alinea. Bijvoorbeeld, het tweede item in een lijst die begint bij 5 retourneert
6..
Behoud IParagraphFormat::get_Depth bij elke alinea om het insluitsniveau te behouden. De werkelijke marker codeert niet de volledige hiërarchie: een genest item kan c. retourneren in plaats van een gecombineerd label zoals 6.c..
Het volgende zelfstandige voorbeeld maakt lijsten, slaat ze op in een presentatie en laadt de presentatie opnieuw om voor elke alinea de tekst, diepte, opsommingstype en werkelijke waarde te rapporteren. De kleine blauwe afbeeldings‑marker wordt gemaakt vanuit inline SVG.
#include <DOM/BulletType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IBulletFormat.h>
#include <DOM/IBulletFormatEffectiveData.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IImageCollection.h>
#include <DOM/ILineFormat.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IParagraphFormatEffectiveData.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/ITextFrame.h>
#include <DOM/FillType.h>
#include <DOM/NullableBool.h>
#include <DOM/NumberedBulletStyle.h>
#include <DOM/Paragraph.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <DOM/SvgImage.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/console.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;
{
auto presentation = System::MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(720, 440, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 30, 20, 660, 400);
shape->get_FillFormat()->set_FillType(FillType::NoFill);
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
auto textFrame = shape->get_TextFrame();
textFrame->get_Paragraphs()->Clear();
// Maak een afbeeldingsmarker zonder extern afbeeldingsbestand.
auto svg = System::MakeObject<SvgImage>(u"<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><rect width='16' height='16' rx='4' fill='#0078D4'/></svg>");
auto bulletImage = presentation->get_Images()->AddImage(svg);
auto addParagraph = [&](System::String text, int16_t depth, BulletType type, int16_t start = 1, NumberedBulletStyle style = NumberedBulletStyle::BulletArabicPeriod)
{
auto paragraph = System::MakeObject<Paragraph>();
paragraph->set_Text(text);
auto format = paragraph->get_ParagraphFormat();
format->set_Depth(depth);
format->set_MarginLeft(30 + depth * 40);
format->set_Indent(-28);
format->set_SpaceAfter(8);
format->get_DefaultPortionFormat()->set_FontHeight(22);
format->get_DefaultPortionFormat()->get_FillFormat()->set_FillType(FillType::Solid);
format->get_DefaultPortionFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());
auto bullet = format->get_Bullet();
bullet->set_Type(type);
bullet->set_IsBulletHardColor(NullableBool::True);
bullet->get_Color()->set_Color(Color::get_Black());
if (type == BulletType::Numbered)
{
bullet->set_NumberedBulletStyle(style);
bullet->set_NumberedBulletStartWith(start);
}
else if (type == BulletType::Symbol)
{
bullet->set_Char(u'\u2022');
}
else if (type == BulletType::Picture)
{
bullet->get_Picture()->set_Image(bulletImage);
}
textFrame->get_Paragraphs()->Add(paragraph);
};
addParagraph(u"First item", 0, BulletType::Numbered, 5);
addParagraph(u"Second item", 0, BulletType::Numbered, 5);
addParagraph(u"Nested item", 1, BulletType::Numbered, 3, NumberedBulletStyle::BulletAlphaLCPeriod);
addParagraph(u"Next nested item", 1, BulletType::Numbered, 3, NumberedBulletStyle::BulletAlphaLCPeriod);
addParagraph(u"Deep item", 2, BulletType::Numbered, 4, NumberedBulletStyle::BulletRomanLCPeriod);
addParagraph(u"Back to top level", 0, BulletType::Numbered, 5);
addParagraph(u"Symbol marker", 0, BulletType::Symbol);
addParagraph(u"No bullet", 0, BulletType::None);
addParagraph(u"Picture marker", 0, BulletType::Picture);
presentation->Save(u"actual_bullet_values.pptx", SaveFormat::Pptx);
presentation->Dispose();
}
auto loadedPresentation = System::MakeObject<Presentation>(u"actual_bullet_values.pptx");
auto loadedShape = System::ExplicitCast<IAutoShape>(loadedPresentation->get_Slide(0)->get_Shape(0));
System::Console::WriteLine(u"Text | Depth | Type | Actual value");
for (auto paragraph : loadedShape->get_TextFrame()->get_Paragraphs())
{
auto bullet = paragraph->get_ParagraphFormat()->GetEffective()->get_Bullet();
auto actualValue = bullet->get_ActualBulletValue();
System::String marker;
switch (bullet->get_Type())
{
case BulletType::Numbered:
case BulletType::Symbol:
marker = actualValue;
break;
case BulletType::None:
marker = (actualValue.IsNull() ? System::String(u"null") : actualValue) + u" (no bullet)";
break;
case BulletType::Picture:
marker = (actualValue.IsNull() ? System::String(u"null") : actualValue) + u" (image required)";
break;
default:
marker = u"unsupported bullet type";
break;
}
System::Console::WriteLine(u"{0} | {1} | {2} | {3}", paragraph->get_Text(), paragraph->get_ParagraphFormat()->get_Depth(), bullet->get_Type(), marker);
}
loadedPresentation->Dispose();
De bron‑lijsten worden hieronder getoond.

Het rapport komt overeen met de markers die in PowerPoint worden weergegeven:
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 | null (no bullet)
Picture marker | 0 | Picture | null (image required)
Voor BulletType::None and BulletType::Picture retourneert get_ActualBulletValue een null System::String, niet een lege tekenreeks. Gebruik IsNull om deze waarde te controleren. Behandel deze typen afzonderlijk: het eerste heeft geen marker, terwijl het tweede vereist dat de opsommingafbeelding apart wordt geëxtraheerd. Een afbeeldings‑opsomming kan niet uitsluitend worden gereproduceerd door alleen een tekstreeks‑marker te extraheren.
FAQ
Kunnen opsomming‑ en genummerde lijsten worden geëxporteerd naar PDF of afbeeldingen?
Ja. Aspose.Slides behoudt de lijstopmaak wanneer het doel‑formaat de overeenkomstige tekstindeling en opsommingsfuncties ondersteunt.
Kan ik lijsten bewerken in bestaande presentaties?
Ja. Laad de presentatie, benader de doel‑alinea, inspecteer of werk de instellingen van IParagraphFormat::get_Bullet bij, en sla de presentatie op.
Kunnen lijsten niet‑Latijnse tekst bevatten?
Ja. De tekst van een lijstitem kan Unicode‑tekens bevatten, zodat u lijsten kunt maken in meertalige presentaties. Zorg ervoor dat de in de presentatie gebruikte lettertypen de benodigde tekens ondersteunen.