ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Python/python-pptx 사용자 가이드 - 15. Concepts
    코딩/Python 2024. 6. 12. 15:21
    728x90

    https://python-pptx.readthedocs.io/en/latest/user/concepts.html

    Concepts

    python-pptx is completely object-oriented, and in general any operations you perform with it will be on an object. The root object for a presentation is Presentation. API details are provided on the modules pages, but here are some basics to get you started, especially some relationships you might find surprising at first.

    A presentation is loaded by constructing a new Presentation instance, passing in the path to a presentation to be loaded:

    python-pptx는 완전히 객체 지향적이며 일반적으로 이를 사용하여 수행하는 모든 작업은 객체에서 수행된다. 프레젠테이션의 루트 개체는 프레젠테이션이다. API 세부 정보는 모듈 페이지에 제공되지만 시작하는 데 도움이 되는 몇 가지 기본 사항, 특히 처음에는 놀라울 수 있는 일부 관계가 있다.

    새 Presentation 인스턴스를 생성하고 로드할 프레젠테이션 경로를 전달하여 프레젠테이션을 로드한다.

    from pptx import Presentation
    
    path = 'slide-deck-foo.pptx'
    prs = Presentation(path)

    python-pptx also contains a default template, and if you construct a Presentation instance without a path, a presentation based on that default template is loaded. This can be handy when you want to get started quickly, and most of the examples in this documentation use the default template.:

    python-pptx에는 기본 템플릿도 포함되어 있으며, 경로 없이 프레젠테이션 인스턴스를 생성하면 해당 기본 템플릿을 기반으로 하는 프레젠테이션이 로드된다. 이는 빠르게 시작하려는 경우 유용할 수 있으며 이 문서에 있는 대부분의 예제에서는 기본 템플릿을 사용한다.

    # start with default presentation
    prs = Presentation()

    Note that there is currently no distinction between templates and presentations in python-pptx as there is in the PowerPoint® client, there are only presentations. To use a “template” for a presentation you simply create a presentation with all the styles, logo, and layouts you want, delete all the slides (or leave some in if it suits), and then load that as your starting place.

    현재 PowerPoint® 클라이언트와 마찬가지로 python-pptx에서는 템플릿과 프리젠테이션 사이에 차이가 없으며 프리젠테이션만 있다. 프리젠테이션에 "템플릿"을 사용하려면 원하는 모든 스타일, 로고 및 레이아웃이 포함된 프리젠테이션을 만들고 모든 슬라이드를 삭제(또는 적합한 경우 일부를 남겨두기)한 다음 이를 시작 위치로 로드하면 된다.

    Slide masters

    A presentation has a list of slide masters and a list of slides. Let’s start with a discussion of the slide masters.

    One fact some find surprising (I did) is that a presentation file can have more than one slide master. It’s quite uncommon in my experience to find presentations that make use of this feature, but it’s entirely supported. The only time I’ve seen this happen is when slides from a “foreign” presentation are pasted into another deck; if you want the formatting and backgrounds from the other deck to be preserved on the pasted-in slides, the slide master and its slide layouts need to come with. Consequently, the presentation needs to maintain a list of slide masters, not just a single one, even though perhaps 99% of the time you only ever use the one. To make things a little easier for the 99% situation, you can refer to the first slide master as though it were the only one:

    프레젠테이션에는 슬라이드 마스터 목록과 슬라이드 목록이 있다. 슬라이드 마스터에 대한 논의부터 시작한다.

    일부 사람들이 놀랍다고 생각하는 사실 중 하나는 프레젠테이션 파일에 슬라이드 마스터가 두 개 이상 있을 수 있다는 것이다. 경험상 이 기능을 활용하는 프레젠테이션을 찾는 것은 매우 드물지만 완전히 지원된다. 이런 일이 일어나는 것을 본 유일한 경우는 "외국" 프리젠테이션의 슬라이드를 다른 데크에 붙여넣을 때였다. 붙여넣은 슬라이드에 다른 데크의 서식과 배경을 유지하려면 슬라이드 마스터와 해당 슬라이드 레이아웃이 함께 제공되어야 한다. 결과적으로, 아마도 99%의 시간 동안 해당 마스터만 사용하더라도 프레젠테이션은 단일 슬라이드 마스터가 아닌 슬라이드 마스터 목록을 유지해야 한다. 99% 상황을 좀 더 쉽게 만들기 위해 첫 번째 슬라이드 마스터를 마치 유일한 슬라이드 마스터인 것처럼 참조할 수 있다.

    prs = Presentation()
    slide_master = prs.slide_masters[0]
    # is equivalent to
    slide_master = prs.slide_master

    Slide layouts

    Another fact that might be surprising is that slide layouts belong to a slide master, not directly to a presentation, so normally you have to access the slide layouts via their slide master. Since this is subject to the same 99% situation described above, the slide layouts belonging to the first slide master can also be accessed directly from the presentation via syntactic sugar:

    또 다른 놀라운 사실은 슬라이드 레이아웃이 프레젠테이션에 직접 속하지 않고 슬라이드 마스터에 속하므로 일반적으로 슬라이드 마스터를 통해 슬라이드 레이아웃에 액세스해야 한다는 것이다. 위에서 설명한 것과 동일한 99% 상황이 적용되므로 첫 번째 슬라이드 마스터에 속한 슬라이드 레이아웃은 구문 설탕을 통해 프레젠테이션에서 직접 액세스할 수도 있다.

    prs = Presentation()
    title_slide_layout = prs.slide_masters[0].slide_layouts[0]
    # is equivalent to:
    title_slide_layout = prs.slide_layouts[0]

    Slides

    The slides in a presentation belong to the presentation object and are accessed using the slides attribute:

    프리젠테이션의 슬라이드는 프리젠테이션 객체에 속하며 슬라이드 속성을 사용하여 액세스된다.

    prs = Presentation(path)
    first_slide = prs.slides[0]

    Adding a slide

    Adding a slide is accomplished by calling the add_slide() method on the slides attribute of the presentation. A slide layout must be passed in to specify the layout the new slide should take on:

    슬라이드를 추가하려면 프레젠테이션의 슬라이드 속성에 대해 add_slide() 메서드를 호출하면 된다. 새 슬라이드가 취해야 할 레이아웃을 지정하려면 슬라이드 레이아웃을 전달해야 한다.

    prs = Presentation()
    title_slide_layout = prs.slide_layouts[0]
    new_slide = prs.slides.add_slide(title_slide_layout)

     

    Python/python-pptx 사용자 가이드

    728x90

    댓글

Designed by Tistory.