ส่วน

ตัวอย่างการจัดการส่วนของงานนำเสนอ—เพิ่ม, เข้าถึง, ลบ และเปลี่ยนชื่อโดยใช้ Aspose.Slides for PHP via Java อย่างโปรแกรมเมชัน

เพิ่มส่วน

สร้างส่วนที่เริ่มจากสไลด์เฉพาะ

function addSection() {
    $presentation = new Presentation();
    try {
        $slide = $presentation->getSlides()->get_Item(0);

        // ระบุสไลด์ที่เป็นจุดเริ่มต้นของส่วน.
        $presentation->getSections()->addSection("New Section", $slide);

        $presentation->save("section.pptx", SaveFormat::Pptx);
    } finally {
        $presentation->dispose();
    }
}

เข้าถึงส่วน

อ่านข้อมูลส่วนจากงานนำเสนอ

function accessSection() {
    $presentation = new Presentation("section.pptx");
    try {
        // เข้าถึงส่วนโดยใช้ดัชนี.
        $section = $presentation->getSections()->get_Item(0);
        $sectionName = $section->getName();
    } finally {
        $presentation->dispose();
    }
}

ลบส่วน

ลบส่วนที่ได้เพิ่มไว้ก่อนหน้า

function removeSection() {
    $presentation = new Presentation("section.pptx");
    try {
        $section = $presentation->getSections()->get_Item(0);

        // ลบส่วน.
        $presentation->getSections()->removeSection($section);

        $presentation->save("section_removed.pptx", SaveFormat::Pptx);
    } finally {
        $presentation->dispose();
    }
}

เปลี่ยนชื่อส่วน

เปลี่ยนชื่อของส่วนที่มีอยู่

function renameSection() {
    $presentation = new Presentation("section.pptx");
    try {
        $section = $presentation->getSections()->get_Item(0);
        $section->setName("New Name");

        $presentation->save("section_renamed.pptx", SaveFormat::Pptx);
    } finally {
        $presentation->dispose();
    }
}