Skip to main content

用于生成 PowerPoint 文件的 Python 模块

Project description

edge_pdf 使用说明

概述

edge_pdf 是一个用于生成 PowerPoint 文件的 Python 模块。它提供了一系列方法用于插入表格、文本、图片和图表等内容,并可以保存生成的 PPT 文件。

使用方法

1. 导入模块及类

from edge_pdf import PlaceholderComponent, PPTTable, PPTGenerator

2. 创建 PPTGenerator 实例

ppt = PPTGenerator()

或者使用现有的模板文件创建实例:

template_ppt = "template.pptx"
ppt = PPTGenerator(template_ppt)

3. 插入内容

3.1 插入表格

data = your_data_frame
slide_index = 0 # 第几张幻灯片
placeholder_index = 0 # 占位符索引

ppt.insert_table(data, slide_index, placeholder_index)

3.2 插入文本

content_text = "Your text content"
slide_index = 0 # 第几张幻灯片
placeholder_index = 1 # 占位符索引

ppt.insert_text(content_text, slide_index, placeholder_index)

3.3 插入图片

image_file_path = "path/to/your/image.jpg"
slide_index = 0 # 第几张幻灯片
placeholder_index = 2 # 占位符索引

ppt.insert_picture(image_file_path, slide_index, placeholder_index)

或者从 URL 插入图片:

image_url = "http://example.com/image.jpg"
slide_index = 0 # 第几张幻灯片
placeholder_index = 2 # 占位符索引

ppt.insert_picture(image_url, slide_index, placeholder_index)

3.4 插入图表

chart_type = XL_CHART_TYPE.LINE # 图表类型,参考 pptx.enum.chart.XL_CHART_TYPE
chart_data = your_chart_data
slide_index = 0 # 第几张幻灯片
placeholder_index = 3 # 占位符索引

ppt.insert_chart(chart_type, chart_data, slide_index, placeholder_index)

4. 保存 PPT 文件

output_file = "output.pptx"
ppt.save_ppt(output_file)

注意事项

  • 插入内容时的幻灯片索引和占位符索引都是从0开始的。
  • 插入表格时,数据应为 Pandas DataFrame 对象。

以上就是 PPTGenerator 类的使用说明。希望对您有所帮助!如有任何问题,请随时向我提问。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

edge_pptx-1.0.2.tar.gz (30.7 kB view hashes)

Uploaded Source

Built Distribution

edge_pptx-1.0.2-py3-none-any.whl (30.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page