@@ -33,7 +33,65 @@ def ppt2video(pptx, video, timing, duration,
33
33
# slides_len = len(presentation.Slides)
34
34
35
35
# powerpoint = win32com.client.Dispatch('PowerPoint.Application')
36
- # new_presentation = ppt.Presentations.Add(WithWindow=False)
36
+ new_presentation = ppt .Presentations .Add (WithWindow = False )
37
+ # slides = new_presentation.Slides
38
+ # presentation.Slides[1].Copy()
39
+ # new_presentation.Slides.Paste(1)
40
+ # graphSlideID = gslides.Add(2, ppLayoutChart).SlideID
41
+ # slides.FindBySlideID(graphSlideID)
42
+
43
+
44
+ # Slides indexes start with 1
45
+ for slide in presentation .Slides :
46
+ # print(e.SlideIndex, e.SlideNumber, e.SlideID)
47
+ for key , value in dict .items ():
48
+ # print(slide.SlideIndex, key)
49
+ # print(len(new_presentation.Slides))
50
+ if slide .SlideIndex == int (key ) and value != "" :
51
+ len_new_ppt = len (new_presentation .Slides )
52
+
53
+ print (" slide.SlideIndex == key" , slide .SlideIndex )
54
+
55
+ new_slide = new_presentation .Slides .Add (len_new_ppt + 1 , ppLayoutText )
56
+ new_slide .Shapes .addShape (
57
+ msoShapeRectangle , 150 , 150 , 250 , 250 ). \
58
+ TextFrame .TextRange .Text = value
59
+ slide .Copy ()
60
+ new_presentation .Slides .Paste (len_new_ppt + 2 )
61
+ # else:
62
+ # print("slide.SlideIndex != key", slide.SlideIndex, key)
63
+
64
+
65
+ # if e.SlideIndex == key:
66
+ # print(" e.SlideIndex == key", e.SlideIndex )
67
+ # else:
68
+ # print("e.SlideIndex != key", e.SlideIndex, key)
69
+ # if not presentation.Slides[int(key)]:
70
+ # # e.Copy()
71
+ # # new_presentation.Slides.Paste(length_new_presentation)
72
+ # # length_new_presentation += 1
73
+ # print("no index in dict", e.SlideIndex, e.SlideNumber, e.SlideID)
74
+ # else:
75
+ # if presentation.Slides[int(key)] and value != "":
76
+ # # slide = new_presentation.Slides.Add(length_new_presentation+1, ppLayoutText)
77
+ # # slide.Shapes.addShape(
78
+ # # msoShapeRectangle, 150, 150, 250, 250). \
79
+ # # TextFrame.TextRange.Text = value
80
+ # # e.Copy()
81
+ # # new_presentation.Slides.Paste(length_new_presentation+2)
82
+ # # length_new_presentation += 1
83
+ # print("index in both", e.SlideIndex, e.SlideNumber, e.SlideID)
84
+
85
+
86
+ # for key, value in dict.items():
87
+ # if presentation.Slides[int(key)] and value != "":
88
+ # slide = new_presentation.Slides.Add(int(key)+1, ppLayoutText)
89
+ # slide.Shapes.addShape(
90
+ # msoShapeRectangle, 150, 150, 250, 250). \
91
+ # TextFrame.TextRange.Text = value
92
+ # presentation.Slides[int(key)].Copy()
93
+ # new_presentation.Slides.Paste(int(key)+2)
94
+
37
95
# list_slides = [e for e in presentation.Slides]
38
96
# # for each in presentation.Slides:
39
97
# for key, value in dict.items():
@@ -102,7 +160,7 @@ def ppt2video(pptx, video, timing, duration,
102
160
103
161
# Presentation.CreateVideo method (PowerPoint)
104
162
# https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.createvideo
105
- presentation .CreateVideo (video_path , timing , duration ,
163
+ new_presentation .CreateVideo (video_path , timing , duration ,
106
164
resolution , frames , quality )
107
165
while True :
108
166
try :
@@ -112,6 +170,7 @@ def ppt2video(pptx, video, timing, duration,
112
170
break
113
171
except Exception :
114
172
pass
173
+ new_presentation .Close ()
115
174
presentation .Close ()
116
175
ppt .Quit ()
117
176
pass
@@ -129,7 +188,11 @@ def ppt2video(pptx, video, timing, duration,
129
188
# the first slide. You can leave it blank and no additional
130
189
# slides will be inserted in the video.
131
190
user_input_list = []
132
- input_dict = {"0" :"0" , "1" :"1" , "2" :"2" ,"3" :"3" ,"4" :"4" ,"5" :"" ,"6" :"" ,"7" :"" ,"8" :"" ,"9" :"" }
191
+ # key in the dict represents the index of the slides in the presentation
192
+ # to be converted into video. Slides indexes start with 1, "first slide".
193
+ input_dict = { "1" :"input index 1" ,
194
+ "2" :"input index 2" , "4" :"input index 4" , "5" :"input index 5" ,
195
+ "10" :"input index 10" ,}
133
196
134
197
ppt2video (f"./{ file_name } " , f"./{ video_name } .mp4" ,
135
198
UseTimingsAndNarrations ,
0 commit comments