Gerenciar Listas com Marcadores e Numeradas em Apresentações Usando Python via Java
Visão geral
Aspose.Slides for Python via Java permite criar e formatar listas com marcadores e numeradas em apresentações PowerPoint e OpenDocument. Um item de lista é um parágrafo cujas configurações de marcador são controladas por meio do seu formato de parágrafo.
Use o método Paragraph.getParagraphFormat para acessar as configurações de lista ao nível do parágrafo. O ponto de entrada principal é ParagraphFormat.getBullet, que retorna um objeto BulletFormat. Com esse objeto, você pode definir o tipo de marcador, símbolo, imagem, cor, tamanho, estilo de numeração e número inicial.
Este artigo mostra como:
- criar uma lista com marcadores usando um símbolo personalizado
- criar um marcador de imagem
- criar uma lista multinível definindo a profundidade do parágrafo
- criar uma lista numerada
- inspecionar e alterar a formatação de lista em uma apresentação existente
- ler os marcadores de lista reais e os números ao lado do texto do parágrafo
Criar uma lista com marcadores
Para criar uma lista com marcadores, adicione objetos Paragraph a um TextFrame e defina BulletFormat.setType como BulletType.Symbol. Em seguida, use BulletFormat.setChar, BulletFormat.getColor e BulletFormat.setHeight para controlar a aparência do marcador.
O código Python a seguir demonstra como criar uma lista com marcadores em um slide:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, NullableBool, Paragraph, Presentation, SaveFormat, ShapeType
from java.awt import Color
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
auto_shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 200, 50)
text_frame = auto_shape.getTextFrame()
text_frame.getParagraphs().clear()
bullet_color = Color(205, 92, 92)
first_paragraph = Paragraph()
first_paragraph.getParagraphFormat().getBullet().setType(BulletType.Symbol)
first_paragraph.getParagraphFormat().getBullet().setChar('*')
first_paragraph.getParagraphFormat().setIndent(15)
first_paragraph.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True_)
first_paragraph.getParagraphFormat().getBullet().getColor().setColor(bullet_color)
first_paragraph.getParagraphFormat().getBullet().setHeight(100)
first_paragraph.setText("The first paragraph")
text_frame.getParagraphs().add(first_paragraph)
second_paragraph = Paragraph()
second_paragraph.getParagraphFormat().getBullet().setType(BulletType.Symbol)
second_paragraph.getParagraphFormat().getBullet().setChar('*')
second_paragraph.getParagraphFormat().setIndent(15)
second_paragraph.getParagraphFormat().getBullet().setBulletHardColor(NullableBool.True_)
second_paragraph.getParagraphFormat().getBullet().getColor().setColor(bullet_color)
second_paragraph.getParagraphFormat().getBullet().setHeight(100)
second_paragraph.setText("The second paragraph")
text_frame.getParagraphs().add(second_paragraph)
presentation.save("symbol_bullets.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Resultado:

Criar uma lista numerada
Use listas numeradas quando a ordem dos itens for importante. Defina BulletFormat.setType como BulletType.Numbered. Você também pode escolher um formato de numeração com BulletFormat.setNumberedBulletStyle ou usar BulletFormat.setNumberedBulletStartWith quando a lista deve iniciar em um valor diferente de 1.
O código Python a seguir mostra como criar uma lista numerada em um slide:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, Paragraph, Presentation, SaveFormat, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
auto_shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 90, 80)
text_frame = auto_shape.getTextFrame()
text_frame.getParagraphs().clear()
first_paragraph = Paragraph()
first_paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
first_paragraph.setText("Apple")
text_frame.getParagraphs().add(first_paragraph)
second_paragraph = Paragraph()
second_paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
second_paragraph.setText("Orange")
text_frame.getParagraphs().add(second_paragraph)
third_paragraph = Paragraph()
third_paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
third_paragraph.setText("Banana")
text_frame.getParagraphs().add(third_paragraph)
presentation.save("numbered_bullets.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Resultado:

Criar um marcador de imagem
Aspose.Slides permite substituir um símbolo de marcador regular por uma imagem. Marcadores de imagem funcionam melhor com imagens simples que permanecem legíveis em tamanho pequeno, como ícones ou pequenos arquivos PNG transparentes.
Note
Se você planeja substituir um símbolo de marcador regular por uma imagem, escolha um gráfico simples com fundo transparente. Essas imagens funcionam bem como símbolos de marcador personalizados.Para criar um marcador de imagem, adicione uma imagem a Presentation.getImages e atribua o objeto de imagem retornado a BulletFormat.getPicture. Defina BulletFormat.setType como BulletType.Picture antes de atribuir a imagem.
Suponha que tenhamos uma imagem chamada “image.png”:

O código Python a seguir mostra como criar marcadores de imagem em um slide:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, Images, Paragraph, Presentation, SaveFormat, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
auto_shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 200, 50)
text_frame = auto_shape.getTextFrame()
text_frame.getParagraphs().clear()
image = Images.fromFile("image.png")
try:
bullet_image = presentation.getImages().addImage(image)
finally:
image.dispose()
first_paragraph = Paragraph()
first_paragraph.getParagraphFormat().getBullet().setType(BulletType.Picture)
first_paragraph.getParagraphFormat().getBullet().getPicture().setImage(bullet_image)
first_paragraph.getParagraphFormat().setIndent(15)
first_paragraph.getParagraphFormat().getBullet().setHeight(100)
first_paragraph.setText("The first paragraph")
text_frame.getParagraphs().add(first_paragraph)
second_paragraph = Paragraph()
second_paragraph.getParagraphFormat().getBullet().setType(BulletType.Picture)
second_paragraph.getParagraphFormat().getBullet().getPicture().setImage(bullet_image)
second_paragraph.getParagraphFormat().setIndent(15)
second_paragraph.getParagraphFormat().getBullet().setHeight(100)
second_paragraph.setText("The second paragraph")
text_frame.getParagraphs().add(second_paragraph)
presentation.save("picture_bullets.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Resultado:

Criar uma lista multinível
Use ParagraphFormat.setDepth para posicionar itens de lista em diferentes níveis. O nível 0 é o nível superior, o nível 1 está aninhado abaixo dele e assim por diante.
O código Python a seguir mostra como criar uma lista com marcadores multinível:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Paragraph, Presentation, SaveFormat, ShapeType
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
auto_shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 260, 110)
text_frame = auto_shape.getTextFrame()
text_frame.getParagraphs().clear()
first_paragraph = Paragraph()
first_paragraph.getParagraphFormat().setDepth(0)
first_paragraph.setText("My text - Depth 0")
text_frame.getParagraphs().add(first_paragraph)
second_paragraph = Paragraph()
second_paragraph.getParagraphFormat().setDepth(1)
second_paragraph.setText("My text - Depth 1")
text_frame.getParagraphs().add(second_paragraph)
third_paragraph = Paragraph()
third_paragraph.getParagraphFormat().setDepth(2)
third_paragraph.setText("My text - Depth 2")
text_frame.getParagraphs().add(third_paragraph)
fourth_paragraph = Paragraph()
fourth_paragraph.getParagraphFormat().setDepth(3)
fourth_paragraph.setText("My text - Depth 3")
text_frame.getParagraphs().add(fourth_paragraph)
presentation.save("multilevel_bullets.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Resultado:

Alterar uma lista existente
Para alterar a formatação de lista em uma apresentação existente, acesse o parágrafo de destino e atualize suas configurações de ParagraphFormat.getBullet. As mesmas propriedades usadas para criar listas podem ser usadas para inspecionar ou modificar listas carregadas de um arquivo PPT, PPTX ou ODP.
O código Python a seguir altera o primeiro parágrafo em um quadro de texto para usar um estilo de lista numerada:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, NumberedBulletStyle, Presentation, SaveFormat
presentation = Presentation("input.pptx")
try:
slide = presentation.getSlides().get_Item(0)
auto_shape = slide.getShapes().get_Item(0)
paragraph = auto_shape.getTextFrame().getParagraphs().get_Item(0)
paragraph.getParagraphFormat().getBullet().setType(BulletType.Numbered)
paragraph.getParagraphFormat().getBullet().setNumberedBulletStyle(NumberedBulletStyle.BulletRomanUCPeriod)
paragraph.getParagraphFormat().getBullet().setNumberedBulletStartWith(1)
paragraph.getParagraphFormat().setMarginLeft(30)
paragraph.getParagraphFormat().setIndent(-20)
presentation.save("updated_list.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Ler valores reais de marcadores
Ao extrair conteúdo da apresentação, mantenha os marcadores de lista ao lado do texto do parágrafo. Chame ParagraphFormat.getEffective e acesse getBullet para obter o formato de marcador efetivo. Verifique seu getType antes de ler getActualBulletValue.
Para listas numeradas, diferencie estes três valores:
getNumberedBulletStyledetermina o formato, como números arábicos seguidos de ponto ou letras minúsculas seguidas de ponto.getNumberedBulletStartWithespecifica o número inicial para um grupo de parágrafos numerados.getActualBulletValuedevolve o marcador formatado para um parágrafo específico. Por exemplo, o segundo item em uma lista que começa em 5 retorna6..
Preserve getDepth com cada parágrafo para reter seu nível de aninhamento. O marcador real não codifica a hierarquia completa: um item aninhado pode retornar c. em vez de um rótulo combinado como 6.c..
O exemplo autônomo a seguir cria listas, salva‑as em uma apresentação e recarrega a apresentação para relatar o texto, a profundidade, o tipo de marcador e o valor real de cada parágrafo. O pequeno marcador de imagem azul é criado a partir de SVG embutido.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import BulletType, FillType, NullableBool, NumberedBulletStyle, Paragraph, Presentation, SaveFormat, ShapeType, SlideSizeScaleType, SvgImage
from java.awt import Color
presentation = Presentation()
try:
presentation.getSlideSize().setSize(720, 440, SlideSizeScaleType.DoNotScale)
slide = presentation.getSlides().get_Item(0)
shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 20, 660, 400)
shape.getFillFormat().setFillType(FillType.NoFill)
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill)
text_frame = shape.getTextFrame()
text_frame.getParagraphs().clear()
# Criar um marcador de imagem sem um arquivo de imagem externo.
svg = 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.getImages().addImage(svg)
def add_paragraph(text, depth, bullet_type, start, style):
paragraph = Paragraph()
paragraph.setText(text)
paragraph_format = paragraph.getParagraphFormat()
paragraph_format.setDepth(depth)
paragraph_format.setMarginLeft(30 + depth * 40)
paragraph_format.setIndent(-28)
paragraph_format.setSpaceAfter(8)
paragraph_format.getDefaultPortionFormat().setFontHeight(22)
paragraph_format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid)
paragraph_format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK)
paragraph_format.getBullet().setType(bullet_type)
paragraph_format.getBullet().setBulletHardColor(NullableBool.True_)
paragraph_format.getBullet().getColor().setColor(Color.BLACK)
if bullet_type == BulletType.Numbered:
paragraph_format.getBullet().setNumberedBulletStyle(style)
paragraph_format.getBullet().setNumberedBulletStartWith(start)
elif bullet_type == BulletType.Symbol:
paragraph_format.getBullet().setChar('\u2022')
elif bullet_type == BulletType.Picture:
paragraph_format.getBullet().getPicture().setImage(bullet_image)
text_frame.getParagraphs().add(paragraph)
add_paragraph("First item", 0, BulletType.Numbered, 5, NumberedBulletStyle.BulletArabicPeriod)
add_paragraph("Second item", 0, BulletType.Numbered, 5, NumberedBulletStyle.BulletArabicPeriod)
add_paragraph("Nested item", 1, BulletType.Numbered, 3, NumberedBulletStyle.BulletAlphaLCPeriod)
add_paragraph("Next nested item", 1, BulletType.Numbered, 3, NumberedBulletStyle.BulletAlphaLCPeriod)
add_paragraph("Deep item", 2, BulletType.Numbered, 4, NumberedBulletStyle.BulletRomanLCPeriod)
add_paragraph("Back to top level", 0, BulletType.Numbered, 5, NumberedBulletStyle.BulletArabicPeriod)
add_paragraph("Symbol marker", 0, BulletType.Symbol, 1, NumberedBulletStyle.BulletArabicPeriod)
add_paragraph("No bullet", 0, BulletType.None_, 1, NumberedBulletStyle.BulletArabicPeriod)
add_paragraph("Picture marker", 0, BulletType.Picture, 1, NumberedBulletStyle.BulletArabicPeriod)
presentation.save("actual_bullet_values.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
loaded_presentation = Presentation("actual_bullet_values.pptx")
try:
loaded_shape = loaded_presentation.getSlides().get_Item(0).getShapes().get_Item(0)
type_names = {
BulletType.Numbered: "Numbered",
BulletType.Symbol: "Symbol",
BulletType.None_: "None",
BulletType.Picture: "Picture",
}
print("Text | Depth | Type | Actual value")
for paragraph in loaded_shape.getTextFrame().getParagraphs():
bullet = paragraph.getParagraphFormat().getEffective().getBullet()
bullet_type = bullet.getType()
if bullet_type in (BulletType.Numbered, BulletType.Symbol):
marker = bullet.getActualBulletValue()
elif bullet_type == BulletType.None_:
marker = f"{bullet.getActualBulletValue()} (no bullet)"
elif bullet_type == BulletType.Picture:
marker = f"{bullet.getActualBulletValue()} (image required)"
else:
marker = "unsupported bullet type"
type_name = type_names.get(bullet_type, "Unknown")
print(f"{paragraph.getText()} | {paragraph.getParagraphFormat().getDepth()} | {type_name} | {marker}")
finally:
loaded_presentation.dispose()
As listas de origem são mostradas abaixo.

O relatório corresponde aos marcadores exibidos no 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)
Para BulletType.None_ and BulletType.Picture, getActualBulletValue devolve None (Java null), não uma string vazia. Trate esses tipos separadamente: o primeiro não possui marcador, enquanto o último requer a extração da imagem do marcador separadamente. Um marcador de imagem não pode ser reproduzido apenas extraindo um marcador de texto.
Perguntas frequentes
É possível exportar listas com marcadores e numeradas para PDF ou imagens?
Sim. Aspose.Slides preserva a formatação de lista quando o formato de destino oferece suporte ao layout de texto e aos recursos de marcador correspondentes.
Posso editar listas em apresentações existentes?
Sim. Carregue a apresentação, acesse o parágrafo de destino, inspecione ou atualize suas configurações de ParagraphFormat.getBullet e salve a apresentação.
Listas podem conter texto não latino?
Sim. O texto dos itens de lista pode conter caracteres Unicode, de modo que você pode criar listas em apresentações multilíngues. Certifique‑se de que as fontes usadas na apresentação suportem os caracteres necessários.