Powerpoint не закрывается - Tcl - TWAPI - PullRequest
1 голос
/ 14 июня 2019

Я создал скрипт tcl, который должен выполнять следующие действия:

  1. Открыть объект PPT
  2. Добавить новый слайд
  3. Вставка файлов анимации (.avi).
  4. Сохранить файл
  5. Закрыть ppt

Все отлично работает, но в конце ppt не закрывается. Вот код, который я написал. Есть что-то, что я пропускаю?

set job_folder "C:\\Users\\xcxc\\Desktop\\test_ui\\test" 

set num_of_modes 15

#get the directory#
set dirname [file dirname [info script]]
set template_dirname "$dirname/Report_Template.pptx"


#handle the files#

file copy -force "$dirname/Report_Template.pptx" "$job_folder/Report/Report.pptx"

#modify the PPts#
package require twapi
set ppt [::twapi::comobj PowerPoint.Application]
$ppt DisplayAlerts [expr 0]
set presents [$ppt Presentations]
$presents Open "$job_folder/Report/Report.pptx"; #Open the Presnetation
set active_presentation [$ppt ActivePresentation]; #get the cureently active presentaatin
set slides [$active_presentation Slides]; #gte the slide list
set slide_1 [$slides Item 1]; #get control on slide index 1


set object_list {}
set mode_counter 1
while {$mode_counter <= $num_of_modes} {
    set slide_num [expr {$mode_counter + 1}]
    set slide_$slide_num [$slides Add $slide_num 12]; #add one more slide into the presentation

    set slide_$slide_num\_shapes [[set slide_$slide_num] Shapes]

    set slide_$slide_num\_video_1 [[set slide_$slide_num\_shapes] AddMediaObject2 [file nativename "$job_folder/Report/Mode_$mode_counter\_Iso_Front.avi"] -1 -1 20 100 650 300]

    set slide_$slide_num\_video_2 [[set slide_$slide_num\_shapes] AddMediaObject2 [file nativename "$job_folder/Modal_Analysis/Report/Mode_$mode_counter\_Iso_Back.avi"] -1 -1 500 100 650 300]


    lappend object_list "slide_$slide_num"
    lappend object_list "slide_$slide_num\_shapes"
    lappend object_list "slide_$slide_num\_video_1"
    lappend object_list "slide_$slide_num\_video_2"

    incr mode_counter 1
}


$active_presentation Save 

foreach object $object_list {
    puts $object
    [set $object] -destroy
}

$slides -destroy
$active_presentation -destroy 


$ppt Quit
$ppt -destroy

Обновление - добавлены $ подарки -destroy

set job_folder "C:\\Users\\xcxc\\Desktop\\test_ui\\test" 

set num_of_modes 15

#get the directory#
set dirname [file dirname [info script]]
set template_dirname "$dirname/Report_Template.pptx"


#handle the files#

file copy -force "$dirname/Report_Template.pptx" "$job_folder/Report/Report.pptx"

#modify the PPts#
package require twapi
set ppt [::twapi::comobj PowerPoint.Application]
$ppt DisplayAlerts [expr 0]
set presents [$ppt Presentations]
$presents Open "$job_folder/Report/Report.pptx"; #Open the Presnetation
set active_presentation [$ppt ActivePresentation]; #get the cureently active presentaatin
set slides [$active_presentation Slides]; #gte the slide list
set slide_1 [$slides Item 1]; #get control on slide index 1


set object_list {}
set mode_counter 1
while {$mode_counter <= $num_of_modes} {
    set slide_num [expr {$mode_counter + 1}]
    set slide_$slide_num [$slides Add $slide_num 12]; #add one more slide into the presentation

    set slide_$slide_num\_shapes [[set slide_$slide_num] Shapes]

    set slide_$slide_num\_video_1 [[set slide_$slide_num\_shapes] AddMediaObject2 [file nativename "$job_folder/Report/Mode_$mode_counter\_Iso_Front.avi"] -1 -1 20 100 650 300]

    set slide_$slide_num\_video_2 [[set slide_$slide_num\_shapes] AddMediaObject2 [file nativename "$job_folder/Modal_Analysis/Report/Mode_$mode_counter\_Iso_Back.avi"] -1 -1 500 100 650 300]


    lappend object_list "slide_$slide_num"
    lappend object_list "slide_$slide_num\_shapes"
    lappend object_list "slide_$slide_num\_video_1"
    lappend object_list "slide_$slide_num\_video_2"

    incr mode_counter 1
}


$active_presentation Save 

foreach object $object_list {
    puts $object
    [set $object] -destroy
}

$slides -destroy
$active_presentation -destroy 

$presents -destroy

$ppt Quit
$ppt -destroy
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...