Skip to main content

使用预定义的布局模板创建可自定义的 PowerPoint 演示文稿 (.pptx)

项目描述

python-pptx-templater 是一个使用 jinja 模板语言创建高度可定制的 PowerPoint 演示文稿的工具。用户指定布局和占位符,模板将呈现演示文稿。

例子

输入

https://raw.githubusercontent.com/kwlo/python-pptx-templater/master/docs/static/images/sample_input.png

使用模板 JSON:

{
    'slides': [
        {
            'layoutSlideNum': 0,
            'text': {
                'name': 'Paul'
            }
        },
        {
            'layoutSlideNum': 0,
            'text': {
                'name': 'Joe'
            }
        },
        {
            'layoutSlideNum': 1,
            'text': {
                'dog': {
                    'name': 'John Cena'
                }
            }
        },
    ]
}

输出

https://raw.githubusercontent.com/kwlo/python-pptx-templater/master/docs/static/images/sample_output.png

安装

pip install python-pptx-templater

用法

from pptx_templater.core import convert


def test_conversion():
    currpwd = os.path.dirname(os.path.abspath(__file__))
    srcpath = f'{currpwd}/fixtures/test_presentation_layout.pptx'
    destpath = f'{currpwd}/test_outputs/updated.pptx'

    j = {
        'slides': [
            {
                'layoutSlideNum': 0,
                'text': {
                    'name': 'Paul'
                }
            },
            {
                'layoutSlideNum': 0,
                'text': {
                    'name': 'Joe'
                }
            },
            {
                'layoutSlideNum': 1,
                'text': {
                    'dog': {
                        'name': 'John Cena'
                    }
                }
            },
        ]
    }

    convert(srcpath, destpath, j)

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

python-pptx-templater-1.1.15.tar.gz (3.5 kB 查看哈希

已上传 source

内置分布

python_pptx_templater-1.1.15-py3-none-any.whl (5.2 kB 查看哈希

已上传 py3