37,719
社区成员
发帖
与我相关
我的任务
分享
import win32com.client, sys 我删除了这个以后,下面在这里就报错了
import os
import math
if __name__ == '__main__':
current_address = os.path.dirname(os.path.abspath(__file__))
#--------------------用二维列表存放每个PPT的相对地址
print('---------------------------------------------------------------------------------')
print(' 各模块PPT文件信息')
print('---------------------------------------------------------------------------------')
path_list =[[0 for col in range(20)] for row in range(20)] # 创建20*20的二维列表,存放每个PPT文件的地址
module_index = 0
for parent, dirnames, filenames in os.walk(current_address):
for each_module in dirnames:
module_index = module_index + 1
# module_name[module_index] = each_module
print("module", module_index, ":", each_module)
file_index = 0
file_list = os.listdir(each_module) # 获取each_module下面的所有PPT文件的名字
for each_file in file_list:
file_index = file_index + 1
print("file", file_index, ":", each_file)
file_path = current_address + '\\' + each_module + '\\' + each_file # 每个PPT文件地址 = 代码所在文件夹 + 模块名 + 文件名
file_path = file_path.replace('\\', '/') #绝对路径转为相对路径
path_list[module_index][file_index] = file_path
# print(list[module_index][file_index])
#-----------------------用vector存放用户的选择,格式:<模块序号,文件序号>
print()
print('---------------------------------------------------------------------------------')
print(' 请按顺序输入您选择的PPT文件,输入格式为:模块序号 文件序号')
print(' 所有文件选择完毕后,请输入:0 0')
print('---------------------------------------------------------------------------------')
class Vector(object):
def __init__(self, x, y):
self.x = x
self.y = y
m = 1
n = 1
choice_list = {}
i = 1
while m > 0:
print('您选择的第', i, '个PPT文件:',end='')
m, n = map(int, input().split())
v = Vector(m, n)
choice_list[i] = v
i = i + 1
# print(choice_list)
#-----------------------遍历choice,合并PPT
Application = win32com.client.Dispatch("PowerPoint.Application")
Application.Visible = True
# 创建一个新的空白PPT对象
new_ppt = Application.Presentations.Add()
for each_choice in choice_list:
# print(each_choice)
# print(choice_list[each_choice])
# print(choice_list[each_choice].module())
file_path = path_list[choice_list[each_choice].x][choice_list[each_choice].y]
exit_ppt = Application.Presentations.Open(file_path)
page_num = exit_ppt.Slides.Count
exit_ppt.Close()
num = new_ppt.Slides.InsertFromFile(file_path, new_ppt.Slides.Count, 1, page_num)
# new_ppt.SaveAs(r'D:\python作业集\合并PPT\new_ppt.pptx')
Presentation.Save()
Application.Quit()