티스토리 뷰

파워포인트를 자동으로 작성하기 위한 파이썬 코드

 

[Test code]

def Test12():
        from BPowerpoint import cPowerpoint
        from pptx import Presentation
        from pptx.util import Cm

        prst1 = cPowerpoint()
        ppt1 = Presentation()
        pptTitle = "Title for Test12"
        #ppt1 = Presentation(pptTemplateFile)
        #ppt1.apply_theme(pptTemplateFile)
        ppt1.slide_width = Cm(29.7)
        ppt1.slide_height = Cm(21)
        pptxName = "./Test12.pptx"
        layout0 = ppt1.slide_layouts[0]
        slide0 = ppt1.slides.add_slide(layout0)
        titleNotesString = "Note for Test12"
        prst1.SetTitleSlide(slide0, pptTitle, "2023.", titleNotesString)
        layout1 = ppt1.slide_layouts[1]
        slide1 = ppt1.slides.add_slide(layout1)

        countryCode1 = "US"
        folderPath1 = "./BDSData/Hot20Images"
        fileListAll = os.listdir(folderPath1)
        fileInitial_New = countryCode1 + "_ASBN_"
        fileInitial_Existing  = countryCode1 + "_ASBE_"
        newItemImages = []
        existingItemImages = []
        for file11 in fileListAll:
            if file11.find(fileInitial_New): newItemImages.append(folderPath1 + "/" + file11)
            if file11.find(fileInitial_Existing): existingItemImages.append(folderPath1 + "/" + file11)

        newItemImages.sort()
        existingItemImages.sort()
        print("[New]", newItemImages)
        print("[Existing]", existingItemImages)
        #return
        prst1.SetArrangedImageSlide(slide1, "New", newItemImages, )
        slide1 = ppt1.slides.add_slide(layout1)
        prst1.SetArrangedImageSlide(slide1, "Existing", existingItemImages, )

        ppt1.save(pptxName)

 

 

반응형