管理项目符号

Microsoft PowerPoint 中,您可以像在 Word 和其他文本编辑器中一样创建项目符号和编号列表。Aspose.Slides for Node.js via Java 还允许您在演示文稿的幻灯片中使用项目符号和编号。

为什么使用项目符号列表?

项目符号列表帮助您快速高效地组织和呈现信息。

项目符号列表示例

在大多数情况下,项目符号列表具备以下三个主要功能:

  • 吸引读者或观众注意重要信息
  • 让读者或观众轻松浏览关键要点
  • 高效地传达重要细节。

为什么使用编号列表?

编号列表同样有助于组织和呈现信息。当条目的顺序(例如 step 1, step 2 等)重要,或需要引用条目(例如 see step 3)时,理想情况下应使用数字代替项目符号。

编号列表示例

以下是 Creating Bullets 过程中的步骤摘要(第1步至第15步):

  1. 创建 Presentation 类的实例。
  2. 执行多个任务(第3步至第14步)。
  3. 保存演示文稿。

创建项目符号

本主题也是管理文本段落系列主题的一部分。此页将演示如何管理段落项目符号。项目符号在需要分步骤描述的情况下尤为有用,并且使用项目符号后文本看起来更有条理。带项目符号的段落始终更易阅读和理解。我们将看到开发者如何使用 Aspose.Slides for Node.js via Java 的这一小而强大功能。请按以下步骤使用 Aspose.Slides for Node.js via Java 管理段落项目符号:

  1. 创建 Presentation 类的实例。
  2. 使用 Slide 对象访问幻灯片集合中的所需幻灯片。
  3. 在选定的幻灯片中添加 AutoShape
  4. 访问已添加形状的 TextFrame
  5. 删除 TextFrame 中的默认段落。
  6. 使用 Paragraph 类创建第一个段落实例。
  7. 设置段落的项目符号类型。
  8. 将项目符号类型设置为 Symbol 并设置项目符号字符。
  9. 设置段落文本。
  10. 设置段落缩进以设置项目符号。
  11. 设置项目符号的颜色。
  12. 设置项目符号的高度。
  13. 将创建的段落添加到 TextFrame 的段落集合中。
  14. 添加第二个段落并重复步骤 7 到 13 中的过程。
  15. 保存演示文稿。
// 实例化一个表示 PPTX 文件的 Presentation 类
var pres = new aspose.slides.Presentation();
try {
    // 访问第一张幻灯片
    var slide = pres.getSlides().get_Item(0);
    // 添加并访问自动形状
    var aShp = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
    // 访问创建的自动形状的文本框
    var txtFrm = aShp.getTextFrame();
    // 删除默认的现有段落
    txtFrm.getParagraphs().removeAt(0);
    // 创建一个段落
    var para = new aspose.slides.Paragraph();
    // 设置段落项目符号样式和符号
    para.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
    para.getParagraphFormat().getBullet().setChar(8226);
    // 设置段落文本
    para.setText("Welcome to Aspose.Slides");
    // 设置项目符号缩进
    para.getParagraphFormat().setIndent(25);
    // 设置项目符号颜色
    para.getParagraphFormat().getBullet().getColor().setColorType(aspose.slides.ColorType.RGB);
    para.getParagraphFormat().getBullet().getColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
    // 将 IsBulletHardColor 设置为 true 以使用自定义项目符号颜色
    para.getParagraphFormat().getBullet().isBulletHardColor();
    // 设置项目符号高度
    para.getParagraphFormat().getBullet().setHeight(100);
    // 将段落添加到文本框
    txtFrm.getParagraphs().add(para);
    // 将演示文稿保存为 PPTX 文件
    pres.save("Bullet.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    pres.dispose();
}

创建图片项目符号

Aspose.Slides for Node.js via Java 允许您更改项目符号列表中的项目符号。您可以使用自定义符号或图像替换项目符号。如果希望为列表添加视觉趣味或让列表中的条目更突出,可以使用自己的图像作为项目符号。

创建图片项目符号,请按以下步骤操作:

  1. 创建 Presentation 类的实例
  2. 使用 Slide 对象访问幻灯片集合中的所需幻灯片
  3. 在选定的幻灯片中添加 autoshape
  4. 访问已添加形状的 TextFrame
  5. 删除 TextFrame 中的默认段落
  6. 使用 Paragraph 类创建第一个段落实例
  7. PPImage 中从磁盘加载图像
  8. 将项目符号类型设置为 Picture 并设置图像
  9. 设置段落文本
  10. 设置段落缩进以设置项目符号
  11. 设置项目符号的颜色
  12. 设置项目符号的高度
  13. 将创建的段落添加到 TextFrame 段落集合中
  14. 添加第二个段落并重复前述步骤
  15. 保存演示文稿
var pres = new aspose.slides.Presentation();
try {
    // 访问第一张幻灯片
    var slide = pres.getSlides().get_Item(0);
    // 实例化用于项目符号的图像
    var picture;
    var image = aspose.slides.Images.fromFile("asp1.jpg");
    try {
        picture = pres.getImages().addImage(image);
    } finally {
        if (image != null) {
            image.dispose();
        }
    }
    // 添加并访问自动形状
    var aShp = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
    // 访问创建的自动形状的文本框
    var txtFrm = aShp.getTextFrame();
    // 删除默认的现有段落
    txtFrm.getParagraphs().removeAt(0);
    // 创建新段落
    var para = new aspose.slides.Paragraph();
    para.setText("Welcome to Aspose.Slides");
    // 设置段落项目符号样式和图像
    para.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Picture);
    para.getParagraphFormat().getBullet().getPicture().setImage(picture);
    // 设置项目符号高度
    para.getParagraphFormat().getBullet().setHeight(100);
    // 将段落添加到文本框
    txtFrm.getParagraphs().add(para);
    // 将演示文稿写入为 PPTX 文件
    pres.save("Bullet.pptx", aspose.slides.SaveFormat.Pptx);
} catch (e) {console.log(e);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

创建多级项目符号

要创建包含不同层级项目的项目符号列表(主列表下的子列表),请按以下步骤操作:

  1. 创建 Presentation 类的实例。
  2. 使用 Slide 对象访问幻灯片集合中的所需幻灯片。
  3. 在选定的幻灯片中添加 autoshape。
  4. 访问已添加形状的 TextFrame
  5. 删除 TextFrame 中的默认段落。
  6. 使用 Paragraph 类创建第一个段落实例,并将 depth 设置为 0。
  7. 使用 Paragraph 类创建第二个段落实例,并将 depth 设置为 1。
  8. 使用 Paragraph 类创建第三个段落实例,并将 depth 设置为 2。
  9. 使用 Paragraph 类创建第四个段落实例,并将 depth 设置为 3。
  10. 将创建的段落添加到 TextFrame 段落集合中。
  11. 保存演示文稿。
// 实例化一个表示 PPTX 文件的 Presentation 类
var pres = new aspose.slides.Presentation();
try {
    // 访问第一张幻灯片
    var slide = pres.getSlides().get_Item(0);
    // 添加并访问自动形状
    var aShp = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
    // 访问创建的自动形状的文本框
    var txtFrm = aShp.addTextFrame("");
    // 删除默认的现有段落
    txtFrm.getParagraphs().clear();
    // 创建第一段落
    var para1 = new aspose.slides.Paragraph();
    // 设置段落项目符号样式和符号
    para1.setText("Content");
    para1.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
    para1.getParagraphFormat().getBullet().setChar(8226);
    para1.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
    para1.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
    // 设置项目符号级别
    para1.getParagraphFormat().setDepth(0);
    // 创建第二段落
    var para2 = new aspose.slides.Paragraph();
    // 设置段落项目符号样式和符号
    para2.setText("Second level");
    para2.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
    para2.getParagraphFormat().getBullet().setChar('-');
    para2.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
    para2.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
    // 设置项目符号级别
    para2.getParagraphFormat().setDepth(1);
    // 创建第三段落
    var para3 = new aspose.slides.Paragraph();
    // 设置段落项目符号样式和符号
    para3.setText("Third level");
    para3.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
    para3.getParagraphFormat().getBullet().setChar(8226);
    para3.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
    para3.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
    // 设置项目符号级别
    para3.getParagraphFormat().setDepth(2);
    // 创建第四段落
    var para4 = new aspose.slides.Paragraph();
    // 设置段落项目符号样式和符号
    para4.setText("Fourth Level");
    para4.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Symbol);
    para4.getParagraphFormat().getBullet().setChar('-');
    para4.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(java.newByte(aspose.slides.FillType.Solid));
    para4.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(java.getStaticFieldValue("java.awt.Color", "BLACK"));
    // 设置项目符号级别
    para4.getParagraphFormat().setDepth(3);
    // 将段落添加到文本框
    txtFrm.getParagraphs().add(para1);
    txtFrm.getParagraphs().add(para2);
    txtFrm.getParagraphs().add(para3);
    txtFrm.getParagraphs().add(para4);
    // 将演示文稿保存为 PPTX 文件
    pres.save("MultilevelBullet.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

创建自定义编号列表

Aspose.Slides for Node.js via Java 提供了一个简易 API,用于管理具有自定义数字格式的段落。要在段落中添加自定义编号列表,请按以下步骤操作:

  1. 创建 Presentation 类的实例。
  2. 使用 Slide 对象访问幻灯片集合中的所需幻灯片。
  3. 在选定的幻灯片中添加 autoshape。
  4. 访问已添加形状的 TextFrame
  5. 删除 TextFrame 中的默认段落。
  6. 使用 Paragraph 类创建第一个段落实例,并将 NumberedBulletStartWith 设置为 2
  7. 使用 Paragraph 类创建第二个段落实例,并将 NumberedBulletStartWith 设置为 3
  8. 使用 Paragraph 类创建第三个段落实例,并将 NumberedBulletStartWith 设置为 7
  9. 将创建的段落添加到 TextFrame 段落集合中。
  10. 保存演示文稿。
// 实例化一个表示 PPTX 文件的 Presentation 类
var pres = new aspose.slides.Presentation();
try {
    // 访问第一张幻灯片
    var slide = pres.getSlides().get_Item(0);
    // 添加并访问自动形状
    var aShp = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 200, 200, 400, 200);
    // 访问创建的自动形状的文本框
    var txtFrm = aShp.addTextFrame("");
    // 删除默认的现有段落
    txtFrm.getParagraphs().clear();
    // 第一个列表
    var paragraph1 = new aspose.slides.Paragraph();
    paragraph1.setText("bullet 2");
    paragraph1.getParagraphFormat().setDepth(4);
    paragraph1.getParagraphFormat().getBullet().setNumberedBulletStartWith(2);
    paragraph1.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Numbered);
    txtFrm.getParagraphs().add(paragraph1);
    var paragraph2 = new aspose.slides.Paragraph();
    paragraph2.setText("bullet 3");
    paragraph2.getParagraphFormat().setDepth(4);
    paragraph2.getParagraphFormat().getBullet().setNumberedBulletStartWith(3);
    paragraph2.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Numbered);
    txtFrm.getParagraphs().add(paragraph2);
    // 第二个列表
    var paragraph5 = new aspose.slides.Paragraph();
    paragraph5.setText("bullet 5");
    paragraph5.getParagraphFormat().setDepth(4);
    paragraph5.getParagraphFormat().getBullet().setNumberedBulletStartWith(5);
    paragraph5.getParagraphFormat().getBullet().setType(aspose.slides.BulletType.Numbered);
    txtFrm.getParagraphs().add(paragraph5);
    pres.save(resourcesOutputPath + "SetCustomBulletsNumber-slides.pptx.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

FAQ

Can bulleted and numbered lists created with Aspose.Slides be exported to other formats such as PDF or images?

是的,Aspose.Slides 在将演示文稿导出为 PDF、图像等格式时会完整保留项目符号和编号列表的格式和结构,确保结果一致。

Is it possible to import bullet or numbered lists from existing presentations?

是的,Aspose.Slides 允许您导入并编辑现有演示文稿中的项目符号或编号列表,同时保持其原有的格式和外观。

Does Aspose.Slides support bullet and numbered lists in presentations created in multiple languages?

是的,Aspose.Slides 完全支持多语言演示文稿,您可以使用任何语言(包括特殊字符或非拉丁字符)创建项目符号和编号列表。