当前位置: 首页>>代码示例>>Python>>正文


Python util.Inches方法代码示例

本文整理汇总了Python中pptx.util.Inches方法的典型用法代码示例。如果您正苦于以下问题:Python util.Inches方法的具体用法?Python util.Inches怎么用?Python util.Inches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pptx.util的用法示例。


在下文中一共展示了util.Inches方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pic_to_ppt

# 需要导入模块: from pptx import util [as 别名]
# 或者: from pptx.util import Inches [as 别名]
def pic_to_ppt(filename):  #前提是图片文件名全为数字,否则还需要修改
    if not os.path.exists(filename):
        os.mkdir(filename)
    
    ppt = pptx.Presentation()
    pic_path=[]  
    for i in os.walk(filename).__next__()[2]:
        if i.endswith('.png'):
            pic_path.append(i)
    #若是不全为数字,则可尝试运行下列代码
#    ls=[]
#    for png in pic_path:
#        s=''
#        for item in png:
#            if item<='9' and item>='0':
#                s+=item
#        ls.append(s+'.png')
#    pic_path=ls
    
    pic_path.sort(key=lambda item:int(item.split('.')[0]))
    for i in pic_path:
        i='{}/{}'.format(filename,i)
        slide = ppt.slides.add_slide(ppt.slide_layouts[1])
        slide.shapes.add_picture(i, Inches(0), Inches(0), Inches(10), Inches(7.5))
        
    fname='{}/{}.pptx'.format(filename,filename)
    ppt.save(fname)
    print('生成的文件在 {} 文件夹下的 {}.ppt 中'.format(filename,filename)) 
开发者ID:vict-cn,项目名称:crawlBaiduWenku,代码行数:30,代码来源:pic_to_ppt.py

示例2: to_ppt_slide

# 需要导入模块: from pptx import util [as 别名]
# 或者: from pptx.util import Inches [as 别名]
def to_ppt_slide(fig, file_path, append=False, padding=0.5):
    from io import StringIO, BytesIO
    import pptx
    from pptx import Presentation
    from pptx.util import Inches

    # Create in-memory image stream and save figure to it
    image_stream = BytesIO()
    fig.savefig(image_stream)

    if append:
        try:
            # Try opening the file if it already exists
            prs = Presentation(file_path)
        except pptx.exc.PackageNotFoundError:
            prs = Presentation()
    else:
        prs = Presentation()
    # Create a new slide with the blank template
    blank_slide_layout = prs.slide_layouts[6]
    slide = prs.slides.add_slide(blank_slide_layout)

    # Center image without changing its aspect ratio
    slide_width = prs.slide_width.inches - 2 * padding
    slide_height = prs.slide_height.inches - 2 * padding
    fig_width, fig_height = fig.get_size_inches()
    if (fig_width / slide_width) > (fig_height / slide_height):
        # Image fits slide horizontally and must be scaled down vertically
        width = slide_width
        height = width * fig_height / fig_width
        top = padding + (slide_height - height) / 2
        left = padding
    else:
        # Image fits slide vertically and must be scaled down horizontally
        height = slide_height
        width = height * fig_width / fig_height
        left = padding + (slide_width - width) / 2
        top = padding

    # Convert from EMU to inches
    left = Inches(left)
    top = Inches(top)
    height = Inches(height)
    width = Inches(width)

    pic = slide.shapes.add_picture(image_stream, left, top, height=height, width=width)

    prs.save(file_path) 
开发者ID:adamerose,项目名称:pandasgui,代码行数:50,代码来源:image_viewer.py


注:本文中的pptx.util.Inches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。