57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
|
|
from pptx import Presentation
|
||
|
|
from pptx.util import Inches, Pt
|
||
|
|
from pptx.enum.text import PP_ALIGN
|
||
|
|
from pathlib import Path
|
||
|
|
from loguru import logger
|
||
|
|
|
||
|
|
def create_sample_template():
|
||
|
|
prs = Presentation()
|
||
|
|
|
||
|
|
prs.slide_width = Inches(10)
|
||
|
|
prs.slide_height = Inches(7.5)
|
||
|
|
|
||
|
|
logger.info("正在创建23页示例静态PPT模板...")
|
||
|
|
|
||
|
|
for page_num in range(1, 24):
|
||
|
|
slide_layout = prs.slide_layouts[5] if page_num == 1 else prs.slide_layouts[6]
|
||
|
|
slide = prs.slides.add_slide(slide_layout)
|
||
|
|
|
||
|
|
left = Inches(1)
|
||
|
|
top = Inches(0.5)
|
||
|
|
width = Inches(8)
|
||
|
|
height = Inches(1)
|
||
|
|
|
||
|
|
title_box = slide.shapes.add_textbox(left, top, width, height)
|
||
|
|
tf = title_box.text_frame
|
||
|
|
p = tf.paragraphs[0]
|
||
|
|
|
||
|
|
if page_num == 1:
|
||
|
|
p.text = "宏观数据分析报告"
|
||
|
|
p.font.size = Pt(36)
|
||
|
|
else:
|
||
|
|
p.text = f"第 {page_num} 页 - 示例内容"
|
||
|
|
p.font.size = Pt(24)
|
||
|
|
|
||
|
|
p.font.bold = True
|
||
|
|
p.alignment = PP_ALIGN.CENTER
|
||
|
|
|
||
|
|
if page_num not in [4, 5, 7, 10, 13]:
|
||
|
|
content_left = Inches(1)
|
||
|
|
content_top = Inches(2)
|
||
|
|
content_width = Inches(8)
|
||
|
|
content_height = Inches(4)
|
||
|
|
|
||
|
|
content_box = slide.shapes.add_textbox(content_left, content_top, content_width, content_height)
|
||
|
|
content_tf = content_box.text_frame
|
||
|
|
content_tf.text = "这里是静态内容区域,原理固定不变的部分。\n\n定期更新的数据内容将由Python脚本自动生成并替换对应页面。"
|
||
|
|
content_tf.paragraphs[0].font.size = Pt(14)
|
||
|
|
|
||
|
|
output_path = Path(__file__).parent / "static_ppt" / "macro_analysis_template.pptx"
|
||
|
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||
|
|
prs.save(str(output_path))
|
||
|
|
logger.success(f"示例模板已创建: {output_path}")
|
||
|
|
return str(output_path)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
create_sample_template()
|