feat: 幻灯片母版批量处理问题

main
lichaojun 1 year ago
parent cda8a2c688
commit caed894d72

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

@ -0,0 +1,38 @@
Sub 批量修改母版()
Application.ScreenUpdating = False
newMasterName = "创意素材铺YYDS" ' 指定的新母版名称
Set fso = CreateObject("scripting.filesystemobject")
Set ff = fso.GetFolder("C:\Users\Administrator\Desktop\test") 'ThisWorkbook.Path是当前代码文件所在路径路径名可以根据需求修改
ActiveSheet.UsedRange.ClearContents
a = 1
For Each f In ff.Files
If f Like ".ppt" Or f Like ".pptx" Then
' MsgBox "发现" & f.Name
Set Myppt = CreateObject("PowerPoint.Application")
Myppt.Visible = True
Set newppt = Myppt.Presentations.Open(Filename:=f)
Dim master As Object
For Each master In newppt.Designs
master.Name = newMasterName ' 重命名母版
Next master
newppt.Save
newppt.Close
Set newppt = Nothing
Set Myppt = Nothing
Cells(a, 1) = f.Name '相对路径名
Cells(a, 2) = f '全路径名
a = a + 1
End If
Next f
Application.ScreenUpdating = True
End Sub

Binary file not shown.

@ -10,7 +10,7 @@ const config = {
* 则直接使用inputDir作为工作目录
*/
inputDir: '',
// inputDir: 'E:/商品资料汇总/商品资料(2001-2050)/ppt2005-黄继光',
// inputDir: 'E:\商品资料汇总\商品资料(1201-1250)\ppt1234-海姆立克',
// inputDir: 'C:/Users/Administrator/Desktop/test',
// 指定要查找的目录
directoryPath: 'E:/商品资料汇总/商品资料(1201-1250)',

@ -6,6 +6,8 @@ from PIL import Image
import imagehash
import os
from config import Config
from pptx.opc.constants import RELATIONSHIP_TYPE as RT
from pptx.oxml import parse_xml
def get_copyright_image_paths():
# 构建 assets/copyright-img 的相对路径
@ -60,12 +62,20 @@ def remove_copyright_images(pptx_path, copyright_image_paths):
# 定义要删除的关键字符数组(只删除文本框)
del_text_keywords = ["Speaker name and title", "OfficePLUS", "Presenter name", "www.officeplus.cn", "第一PPT模板网-WWW.1PPT.COM"]
# 定义要删除的关键字符数组(删除整页幻灯片)
del_text_keywords_slide = ["如需商用请您自行向版权方购买、获取商用版权。"]
del_text_keywords_slide = ["模板中使用的字体为开源字体","一站式办公内容服务平台"]
# 遍历所有幻灯片母版
# for sld_mstr in prs.slide_masters:
# theme_part = sld_mstr.part.part_related_by(RT.THEME)
# theme = parse_xml(theme_part.blob)
# sld_mstr.name = theme.get("name")
# print(sld_mstr.name)
# 遍历每一页幻灯片
for index, slide in enumerate(prs.slides):
# 遍历幻灯片中的每个形状
for shape in slide.shapes:
# 检查形状是否为图片
if shape.shape_type == 13: # 13 表示图片
# 临时保存图片
@ -89,7 +99,6 @@ def remove_copyright_images(pptx_path, copyright_image_paths):
# 检查形状是否为文本框
if shape.has_text_frame:
text_content = shape.text
print(f"'{os.path.basename(pptx_path)}'在第 {index + 1} 页有文本框,内容为: '{text_content}'")
# 检查文本内容是否包含要删除的关键字符数组中的任意字符
if any(char in text_content for char in del_text_keywords_slide):

Loading…
Cancel
Save