章节

使用 Aspose.Slides for Java 以编程方式管理演示文稿章节的示例——添加、访问、删除和重命名它们。

添加章节

创建一个从特定幻灯片开始的章节。

static void addSection() {
    Presentation presentation = new Presentation();
    try {
        ISlide slide = presentation.getSlides().get_Item(0);

        // 指定标记章节开头的幻灯片。
        presentation.getSections().addSection("New Section", slide);
    } finally {
        presentation.dispose();
    }
}

访问章节

从演示文稿中读取章节信息。

static void accessSection() {
    Presentation presentation = new Presentation();
    try {
        ISlide slide = presentation.getSlides().get_Item(0);

        presentation.getSections().addSection("My Section", slide);

        // 通过索引访问章节。
        ISection section = presentation.getSections().get_Item(0);
        String sectionName = section.getName();
    } finally {
        presentation.dispose();
    }
}

删除章节

删除先前添加的章节。

static void removeSection() {
    Presentation presentation = new Presentation();
    try {
        ISlide slide = presentation.getSlides().get_Item(0);

        ISection section = presentation.getSections().addSection("Temporary Section", slide);

        // 删除第一个章节。
        presentation.getSections().removeSection(section);
    } finally {
        presentation.dispose();
    }
}

重命名章节

更改现有章节的名称。

static void renameSection() {
    Presentation presentation = new Presentation();
    try {
        ISlide slide = presentation.getSlides().get_Item(0);

        presentation.getSections().addSection("Old Name", slide);

        ISection section = presentation.getSections().get_Item(0);
        section.setName("New Name");
    } finally {
        presentation.dispose();
    }
}