From 42ccea084302d39c3ee6df2442081339420cc9c2 Mon Sep 17 00:00:00 2001 From: lichaojun Date: Sat, 9 Nov 2024 18:04:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=B9=E9=87=8F=E4=BF=AE=E6=94=B9ppt?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py-src/set_ppt_prop.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 py-src/set_ppt_prop.py diff --git a/py-src/set_ppt_prop.py b/py-src/set_ppt_prop.py new file mode 100644 index 0000000..666f9e8 --- /dev/null +++ b/py-src/set_ppt_prop.py @@ -0,0 +1,31 @@ +import os +from pptx import Presentation +from config import Config +from pptx.util import Inches + +def set_slides_prop(ppt_path): + prs = Presentation(ppt_path) + + text = "创意素材铺" + # 设置文档属性 + prs.core_properties.title = text + prs.core_properties.subject = text + prs.core_properties.author = text + prs.core_properties.category = text + prs.core_properties.keywords = text + prs.core_properties.comments = text + + # 保存演示文稿 + prs.save(ppt_path) + print(f"'{os.path.basename(ppt_path)}'设置属性成功") + + +def batch_set_slides(directory): + for filename in os.listdir(directory): + if filename.endswith(".pptx") or filename.endswith(".ppt"): + ppt_path = os.path.join(directory, filename) + set_slides_prop(ppt_path) + + +# 调用批量删除函数 +batch_set_slides(Config.get_latest_folder(Config.WORK_PATH))