ActiveX

Trình bày cách thêm, truy cập, xóa và cấu hình các điều khiển ActiveX trong một bản trình chiếu bằng Aspose.Slides for Python via .NET.

Thêm một điều khiển ActiveX

Chèn một điều khiển ActiveX mới.

def add_activex():
    with slides.Presentation() as presentation:
        slide = presentation.slides[0]

        # Thêm một điều khiển ActiveX mới (TextBox).
        control = slide.controls.add_control(slides.ControlType.WINDOWS_MEDIA_PLAYER, 50, 50, 100, 50)

        presentation.save("activex.pptm", slides.export.SaveFormat.PPTM)

Truy cập một điều khiển ActiveX

Đọc thông tin từ điều khiển ActiveX đầu tiên trên slide.

def access_activex():
    with slides.Presentation("activex.pptm") as presentation:
        slide = presentation.slides[0]

        # Truy cập điều khiển ActiveX đầu tiên.
        control = slide.controls[0] if slide.controls else None
        if control is not None:
            # In tên điều khiển.
            print(f"Control Name: {control.name}")

Xóa một điều khiển ActiveX

Xóa một điều khiển ActiveX hiện có khỏi slide.

def remove_activex():
    with slides.Presentation("activex.pptm") as presentation:
        slide = presentation.slides[0]

        if len(slide.controls) > 0:
            # Xóa điều khiển ActiveX đầu tiên.
            slide.controls.remove_at(0)

        presentation.save("activex_removed.pptm", slides.export.SaveFormat.PPTM)

Cài đặt các thuộc tính ActiveX

Cấu hình một số thuộc tính ActiveX.

def set_activex_properties():
    with slides.Presentation("activex.pptm") as presentation:
        slide = presentation.slides[0]

        # Giả sử bộ sưu tập Control chứa ít nhất một Control.
        control = slide.controls[0]

        control.properties.add("Caption", "Click Me")
        control.properties.add("Enabled", "true")

        presentation.save("activex_properties.pptm", slides.export.SaveFormat.PPTM)